Gevorg Gevorg - 4 months ago 22
SQL Question

CURRENT_TIMESTAMP in milliseconds

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

To get the Unix timestamp in seconds in MySQL:

select UNIX_TIMESTAMP();

Details: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp

Not tested PostgreSQL, but according to this site it should work: http://www.raditha.com/postgres/timestamp.php

select round( date_part( 'epoch', now() ) );
Comments