Master Unix timestamp to date conversion in SQL for MySQL, PostgreSQL, and more. Free tool to verify your timestamp conversions!
Unix timestamps are widely used in SQL databases for compact time storage. This guide explains how to convert timestamps to dates and vice versa in MySQL and PostgreSQL, with DevUtils’ free tool for validation.
A Unix timestamp stores time as seconds (or milliseconds) since January 1, 1970, 00:00:00 UTC. For example, 1694870400
is September 16, 2023, 00:00:00 UTC. It’s space-efficient and easy to compare (Keywords: timestamp sql).
FROM_UNIXTIME
SELECT FROM_UNIXTIME(1694870400) AS datetime;
-- Output: 2023-09-16 00:00:00
TO_TIMESTAMP
SELECT TO_TIMESTAMP(1694870400) AS datetime;
-- Output: 2023-09-16 00:00:00
Keywords: convert timestamp to datetime.
UNIX_TIMESTAMP
SELECT UNIX_TIMESTAMP('2023-09-16 00:00:00') AS timestamp;
-- Output: 1694870400
EXTRACT
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2023-09-16 00:00:00') AS timestamp;
-- Output: 1694870400
Keywords: convert datetime to timestamp.
SELECT FROM_UNIXTIME(1694870400000 / 1000) AS datetime;
Keywords: unix timestamp in milliseconds.
DevUtils’ Timestamp Converter is perfect for testing SQL conversions:
SQL timestamp conversions are straightforward with the right functions. DevUtils’ free Timestamp Tool simplifies validation, boosting your database efficiency. Try it today!