Get the current Unix timestamp (seconds from 1970-01-01T00:00:00Z) in SQL.
- MySQL:
UNIX_TIMESTAMP()
- PostgreSQL:
CAST(EXTRACT(epoch FROM NOW()) AS INT)
- MS SQL:
DATEDIFF(s, '1970-01-01', GETUTCDATE())
- Oracle:
(CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE) - DATE'1970-01-01') * 86400
CAST(EXTRACT(epoch FROM NOW()) AS BIGINT)
expression is wrong. NOW() or CURRENT_TIMESTAMP() will give you TIMESTAMP type. Whenepoch
is extracted from that it gives you Unix timestamp in your DB's (or client) time zone, not in UTC! Seems like we must configure our database to work in UTC too!