1

Is there a MySQL way to query based on current MySQL time in milliseconds?

I'm trying:

SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(NOW()) as now_in_mili

but both columns return the same (the 1970 epoch time).

I'm expecting 'now_in_mili' to print current date in milliseconds such as it is possible in JavaScript:

Date.parse(new Date())

informatik01
  • 16,038
  • 10
  • 74
  • 104
Yaniv Peretz
  • 1,118
  • 2
  • 13
  • 22
  • Have a look at the documentation at https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_now, it's really well documented.... – Nico Haase Jan 04 '18 at 15:37

1 Answers1

1

You need to pass an argument to the NOW() function to specify how many digits of fractional seconds you want it to include. It supports microseconds, but if you want milliseconds you can just use NOW(3) and then multiply the result by 1000, like this:

SELECT UNIX_TIMESTAMP(NOW(3))*1000 as now_in_mili
Ike Walker
  • 64,401
  • 14
  • 110
  • 109
  • thanks I guess I was mistaken because both results started very much the same: :) SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(NOW(3))*1000 as now_in_mili – Yaniv Peretz Jan 05 '18 at 07:01