Convert a Unix Timestamp in SQL

Convert Unix timestamps to dates in MySQL with FROM_UNIXTIME and in PostgreSQL with to_timestamp. Verify the expected value with the converter.

Part of the free Unix Timestamp Converter. Runs in your browser — nothing is uploaded.

Convert a Unix Timestamp in SQL

MySQL uses FROM_UNIXTIME(ts) and PostgreSQL uses to_timestamp(ts) to turn epoch seconds into a date. Both depend on the session timezone, so check your expected UTC value with the converter first.

Worked example: Expected value when the session timezone is UTC

SQL

SELECT FROM_UNIXTIME(1700000000);      -- MySQL
SELECT to_timestamp(1700000000);       -- PostgreSQL

Result (UTC session)

2023-11-14 22:13:20   (MySQL)
2023-11-14 22:13:20+00   (PostgreSQL)

Practical tip

Set the session timezone to UTC when comparing results, for example SET time_zone = '+00:00' in MySQL or SET TIME ZONE 'UTC' in PostgreSQL.

How to use this Unix Timestamp

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

Convert a Unix Timestamp in SQL FAQs

How do I get an epoch from a date in SQL?

MySQL: UNIX_TIMESTAMP(date_col). PostgreSQL: EXTRACT(EPOCH FROM date_col). Both return seconds since 1970-01-01 UTC.

Why does FROM_UNIXTIME show a different hour?

It formats in the session timezone. If the server is not on UTC, the displayed hour differs from the UTC value.

More Unix Timestamp pages

Open the full Unix Timestamp tool →