CURRENT_TIMESTAMP in milliseconds

Marsellus Wallace picture Marsellus Wallace · Mar 8, 2012 · Viewed 158.5k times · Source

Is there any way to get milliseconds out of a timestamp in MySql or PostgreSql (or others just out of curiosity)?

SELECT CURRENT_TIMESTAMP
--> 2012-03-08 20:12:06.032572

Is there anything like this:

SELECT CURRENT_MILLISEC
--> 1331255526000

or the only alternative is to use the DATEDIFF from the era?

Answer

Claudio Holanda picture Claudio Holanda · Jan 11, 2015

For MySQL (5.6+) you can do this:

SELECT ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000)

Which will return (e.g.):

1420998416685 --milliseconds