Why doesn't MySQL support millisecond / microsecond precision?

MySQLMySQLi Database

The millisecond/ microsecond precision wasn’t supported in previous versions like 5.6.4. But now MySQL supports millisecond/ microsecond precision with timestamp, datetime, and time.

The official statement.

“MySQL now supports fractional seconds for TIME, DATETIME, and TIMESTAMP values, with up to microsecond precision”.

You can check the MySQL version on your system using the version() method.

mysql> SELECT version();

The following is the output.

+-----------+
| version() |
+-----------+
| 8.0.12    |
+-----------+
1 row in set (0.01 sec)

Let us now see the syntax to check the date difference.

mysql> SELECT DATEDIFF(now(),now());

Output

+-----------------------+
| DATEDIFF(now(),now()) |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.03 sec)

Let us now see another example.

mysql> SELECT now(6);

The following is the output in microseconds.

+-----------------------+
| now(6)
+-----------------------+
|   2018-11-11 17:13:25.485429     |
+-----------------------+
1 row in set (0.00 sec)
raja
Published on 21-Nov-2018 11:54:26
Advertisements