Timestamp SQL Guide
Learn how to work with timestamp SQL — getting the current Unix timestamp, converting timestamps to dates, and dates to timestamps in popular SQL databases.
Timestamp Converter
--
--
--
--
--
Convert seconds to human time
--
--
Current Timestamp in SQL
| Database | Current Unix timestamp |
|---|---|
| MySQL | SELECT UNIX_TIMESTAMP(); |
| PostgreSQL | SELECT EXTRACT(EPOCH FROM now()); |
| SQLite | SELECT strftime('%s','now'); |
| SQL Server | SELECT DATEDIFF(SECOND,'1970-01-01',GETUTCDATE()); |
Timestamp to Date in SQL
MySQL: SELECT FROM_UNIXTIME(1700000000);
PostgreSQL: SELECT to_timestamp(1700000000);
SQLite: SELECT datetime(1700000000,'unixepoch');
Date to Timestamp in SQL
MySQL: SELECT UNIX_TIMESTAMP('2023-11-14 22:13:20');
PostgreSQL: SELECT EXTRACT(EPOCH FROM TIMESTAMP '2023-11-14 22:13:20');