4

I'm able to get approximate time without milliseconds by query

SELECT UNIX_TIMESTAMP(NOW());

but how to get precise current timestamp with milliseconds? For example, after executing the above query I get 1352717640 value, but I want to get 1352717640xxx value.

UPD

And other answers from SO (like this) offers solution like

SELECT UNIX_TIMESTAMP(NOW(3))*1000;

but this query only fills up milliseconds place with '000', but I want to get PRECISE value of milliseconds, like 1352717640937.

In SQLyog:

enter image description here

And in mysql console:

enter image description here

Is it possible at all for MySQL 5.1?

Ksenia
  • 3,453
  • 7
  • 31
  • 63
  • Possible duplicate of [MySQL 5.6 DATETIME doesn't accept milliseconds/microseconds](https://stackoverflow.com/questions/13344994/mysql-5-6-datetime-doesnt-accept-milliseconds-microseconds) – McNets Feb 28 '18 at 13:32
  • @McNets, but my question is completely different... – Ksenia Feb 28 '18 at 13:34
  • 1
    https://stackoverflow.com/a/48098959/3270427 – McNets Feb 28 '18 at 13:40
  • @McNets, but in this answer milliseconds only replaced with '000', but I want to get precise value of milliseconds. – Ksenia Feb 28 '18 at 13:43
  • 2
    Possible duplicate of [mysql UNIX\_TIMESTAMP(now()) - current time in miliseconds](https://stackoverflow.com/questions/48098185/mysql-unix-timestampnow-current-time-in-miliseconds) – Jorge Campos Feb 28 '18 at 13:45

2 Answers2

5

I think you didn't test it, but yes the solution is

SELECT UNIX_TIMESTAMP(NOW(3))*1000;

SQL Fiddle

MySQL 5.6 Schema Setup:

Query 1:

SELECT UNIX_TIMESTAMP(NOW(3))*1000

Results:

| UNIX_TIMESTAMP(NOW(3))*1000 |
|-----------------------------|
|               1519827493419 |
Daniel E.
  • 2,440
  • 1
  • 14
  • 24
1

Mysql 8.0.26

SELECT UNIX_TIMESTAMP(NOW(3))*1000;
-- return float 1672434492831.000

To integer:

SELECT FLOOR(UNIX_TIMESTAMP(NOW(3))*1000);
-- return INT 1672434492831
MTK
  • 3,300
  • 2
  • 33
  • 49