Yaniv Peretz
Yaniv Peretz

Reputation: 1168

MySQL UNIX_TIMESTAMP(now()) - current time in milliseconds

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())

Upvotes: 1

Views: 914

Answers (1)

Ike Walker
Ike Walker

Reputation: 65527

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

Upvotes: 1

Related Questions