heavy rocker dude
heavy rocker dude

Reputation: 2301

Is Unix time the value of a MYSQL timestamp data type? Correct code example to convert from C#?

I found this sample source code for C# from How to convert a Unix timestamp to DateTime and vice versa?:

DateTime date = new DateTime(2011, 4, 1, 12, 0, 0, 0);

DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);

TimeSpan span = (date - epoch);

double unixTime =span.TotalSeconds.Dump();

If I was to insert into a MYSQL table the value of unixTime, would this be equivalent of a MYSQL timestamp datatype value? I just want to confirm this.

Upvotes: 1

Views: 686

Answers (1)

favoretti
favoretti

Reputation: 30167

It depends on the version of MySQL. TIMESTAMP field format has been changed from unixtime to dd-mm-yyyy hh:mm:ss from 5.something. If you want to insert a unixtime into a timestamp field, you should use FROM_UNIXTIME() builtin.

Upvotes: 1

Related Questions