开发者

Which MySQL field(s) should I use to properly store date time with millisecond precision?

开发者 https://www.devze.com 2023-04-03 07:57 出处:网络
I know MySQL only has a second precision when storing datetimes and timestamps. So what is the best, simplest and most robust workaround you would recommend to include milliseconds?

I know MySQL only has a second precision when storing datetimes and timestamps. So what is the best, simplest and most robust workaround you would recommend to include milliseconds?

So far I have seen DECIMAL(17,3) combined with SQL functions, and others serializing the datetime on a VARCHAR. Another idea would be to store the millisecond compo开发者_C百科nent in another column.


From the manual:

"...microseconds cannot be stored into a column of any temporal data type. Any microseconds part is discarded.

As of MySQL 5.0.8, conversion of TIME or DATETIME values to numeric form (for example, by adding +0) results in a double value with a microseconds part of .000000:"

So, it looks like using a doubel is the way to go.

0

精彩评论

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