How to save time in milliseconds in MySQL?

MySQLMySQLi Database

To save time in milliseconds, we can use now(3) function because “milli 3” can be used for te same purpose. Firstly, I will create a table with the help of CREATE command −

mysql> CREATE table MilliSecondDemo
-> (
-> MyTimeInMillSec datetime(3)
-> );
Query OK, 0 rows affected (0.70 sec)

Inserting record into the table −

mysql> INSERT into MilliSecondDemo values(now(3));
Query OK, 1 row affected (0.98 sec)

Let us now view the table records −

mysql> SELECT * from MilliSecondDemo;

The following is the output

+-------------------------+
| MyTimeInMillSec         |
+-------------------------+
| 2018-10-08 15:19:50.202 |
+-------------------------+
1 row in set (0.00 sec)
raja
Published on 18-Oct-2018 13:23:14
Advertisements