MySQL 5.6 DATETIME 不接受毫秒/微秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13344994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:26:27  来源:igfitidea点击:

MySQL 5.6 DATETIME doesn't accept milliseconds/microseconds

mysql

提问by l33t

Running MySQL 5.6.7-rc which allegedly supports fractional seconds in time values. Right...

运行 MySQL 5.6.7-rc 据称支持时间值的小数秒。对...

Try this in MySQL Workbench 5.2.44:

在 MySQL Workbench 5.2.44 中试试这个:

CREATE TABLE T (dt DATETIME);
INSERT INTO T (dt) VALUES ('2012-11-12 13:54:00.123');
SELECT dt FROM T;

The output is this:

输出是这样的:

2012-11-12 13:54:00

What am I missing here?

我在这里缺少什么?

回答by l33t

Found the answer. Data type should be DATETIME(6)for microseconds and DATETIME(3)for milliseconds.

找到了答案。数据类型应该是DATETIME(6)微秒和DATETIME(3)毫秒。

TIMEand TIMESTAMPcolumn types also support fractional seconds with the same syntax.

TIMETIMESTAMP列类型也支持具有相同语法的小数秒。

For more information, consult the MySQL Reference on Fractional Seconds.

有关更多信息,请参阅MySQL Reference on Fractional Seconds

回答by Luke94

to get microseconds in mysql, call

要在 mysql 中获取微秒,请调用

SELECT MICROSECOND(dt) FROM T;