This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-17. For the latest, interactive version please visit https://mariadb.com/kb/.

Cannot millisecond resolution in a DATETIME column using MariaDB 5.5.44

According to all of the documentation I have read, this looks pretty simple to do. But it just does not work. This is the snippet that shows how I defined the column.

id int(12) NOT NULL auto_increment,
  ev_time DATETIME(3) NOT NULL,
  hostname varchar(65) NOT NULL,
  subsys varchar(65),
 

I have tried using both TIMESTAMP and DATETIME, both give me the same results, the trailing 3 digits are always returned with a value of 000. When I insert, it does not matter if I leave the ev_time field blank and let it autofill, or if I put NOW() in the insert, the result is always this output:

| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
| 2018-07-06 07:58:11.000 |
+-------------------------+
 

Why doesn't this work???

Answer Answered by Ian Gilfillan in this comment.

You should specify the precision, for example NOW(3).

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.