Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL 5.6 DATETIME doesn't accept milliseconds/microseconds

Tags:

mysql

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

Try this in 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?

like image 250
l33t Avatar asked Nov 12 '12 13:11

l33t


People also ask

Does MySQL TIMESTAMP have milliseconds?

No. It stores exactly what you asked for. It can store up to microsecond - but you have not asked for this accuracy. You call NOW() - and you get the datetime without milliseconds.

What is the correct datetime format for MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

What is precision of datetime MySQL?

MySQL permits fractional seconds for TIME , DATETIME , and TIMESTAMP values, with up to microseconds (6 digits) precision.

What is the difference between milliseconds and microseconds?

A microsecond is equal to 1000 nanoseconds or 1⁄1,000 of a millisecond. Because the next SI prefix is 1000 times larger, measurements of 10−5 and 10−4 seconds are typically expressed as tens or hundreds of microseconds.


1 Answers

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

TIME and TIMESTAMP column types also support fractional seconds with the same syntax.

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

like image 157
l33t Avatar answered Sep 19 '22 12:09

l33t