开发者

How do you set a date in a mysql update from a milliseconds since epoch value?

开发者 https://www.devze.com 2022-12-12 04:07 出处:网络
I want to fill out some null dates with default dates, which should be the epoch da开发者_如何学Cte.

I want to fill out some null dates with default dates, which should be the epoch da开发者_如何学Cte.

eg set updateDate = somethingtoconvertEpochDateToDateTime(numberofMillisSinceEpoch)


The MySQL DATETIME only represents times to one second resolution, so you mat as well divide your 'millis' by 1000 and use

updateDate = FROM_UNIXTIME( numberofMillisSinceEpoch / 1000 )

If you really need to store date-time information to higher resolution, you could store the milliseconds since epoch in a BIGINT and roll your own conversion functions.

If you need to back fill with the current date time (i.e. now) you can use the UNIX_TIMESTAMP() function with no argument.

0

精彩评论

暂无评论...
验证码 换一张
取 消