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?
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.
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.
MySQL permits fractional seconds for TIME , DATETIME , and TIMESTAMP values, with up to microseconds (6 digits) precision.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With