MySQL Unix Timestamp Converter

Convert Unix epoch timestamps to MySQL dates and back, then copy the FROM_UNIXTIME() and UNIX_TIMESTAMP() queries for your value.

Client-side only, nothing leaves your browser

Auto-detected: seconds  ·  3.7y ago

Conversions

Epoch (seconds)
1679616000
Epoch (milliseconds)
1679616000000
Human Readable
Friday, March 24, 2023 at 04:00:00 AM GMT+4
ISO 8601
2023-03-24T00:00:00.000Z
MySQL DATETIME (UTC)
2023-03-24 00:00:00

MySQL SQL

Unix timestamp to datetime (session time zone)
SELECT FROM_UNIXTIME(1679616000);
Milliseconds to datetime
SELECT FROM_UNIXTIME(1679616000000 / 1000);
As UTC, whatever the session time zone
SELECT DATE_ADD('1970-01-01 00:00:00', INTERVAL 1679616000 SECOND);
Format as text
SELECT FROM_UNIXTIME(1679616000, '%Y-%m-%d %H:%i:%s');

MySQL Unix Timestamps & Epoch

MySQL turns Unix epoch seconds into a DATETIME with FROM_UNIXTIME() and goes the other way with UNIX_TIMESTAMP(). Both use the session time_zone, so the same epoch shows a different wall-clock time on a server set to a local zone. Run SET time_zone = '+00:00' first if you want UTC. A TIMESTAMP column stops at 2038-01-19 03:14:07 UTC, but on 64-bit builds of MySQL 8.0.28 and later the two functions accept values into the year 3001.

Quick Reference

  • FROM_UNIXTIME(epoch): Epoch seconds to DATETIME, in the session time zone
  • FROM_UNIXTIME(epoch, fmt): Epoch seconds to a formatted string
  • UNIX_TIMESTAMP(dt): DATETIME to epoch seconds
  • CONVERT_TZ(dt, from, to): Shift a DATETIME between time zones
  • UTC_TIMESTAMP(): Current UTC date and time

Notable Epoch Values

EventEpoch (seconds)Date
Unix Epoch0January 1, 1970 00:00:00 UTC
1 Billion1000000000September 9, 2001 01:46:40 UTC
Y2K38 (32-bit limit)2147483647January 19, 2038 03:14:07 UTC
2 Billion2000000000May 18, 2033 03:33:20 UTC
Current (approx)~1774000000March 2026

Frequently asked questions

What does FROM_UNIXTIME do?
FROM_UNIXTIME() takes a count of seconds since 1970-01-01 00:00:00 UTC and returns a DATETIME expressed in the session time zone. Pass a second argument and it returns a string instead, using the same format codes as DATE_FORMAT(), so FROM_UNIXTIME(1711238400, '%Y-%m-%d') returns '2024-03-24' on a UTC session. A decimal argument keeps its fractional seconds, up to 6 digits.
What data type should I use for a Unix timestamp in MySQL?
MySQL has no dedicated epoch type, so the choice is between storing the raw number and storing a date. A signed INT runs out at 2038-01-19 03:14:07 UTC, the same limit as the TIMESTAMP column type, so use BIGINT for raw epochs, and always for milliseconds. If you want MySQL's date functions to work on the column, DATETIME covers the years 1000 to 9999 and is never shifted by the session time zone, while TIMESTAMP is converted to UTC on write and back on read.
Does MySQL UNIX_TIMESTAMP use the time zone?
UNIX_TIMESTAMP() reads its argument as a time in the session time zone, and FROM_UNIXTIME() returns its result in that zone too. Check the current setting with SELECT @@session.time_zone, and run SET time_zone = '+00:00' to work in UTC. Named zones such as 'Europe/Amsterdam' in SET time_zone or CONVERT_TZ() only work after the server's time zone tables are loaded.
How do I get a Unix timestamp in milliseconds in MySQL?
UNIX_TIMESTAMP() returns whole seconds unless its argument carries a fractional part, so ask for the current time with millisecond precision and scale it: SELECT ROUND(UNIX_TIMESTAMP(NOW(3)) * 1000); To read a millisecond value back, divide by 1000 first: FROM_UNIXTIME(1711238400123 / 1000) returns 2024-03-24 00:00:00.1230 on a UTC session.
Why does MySQL FROM_UNIXTIME return NULL?
The usual cause is a 13-digit millisecond value, which lands far past the function's upper limit. In our tests on MySQL 8.4, FROM_UNIXTIME() also returned NULL for negative values and for anything after 3001-01-18 23:59:59 UTC. On 32-bit platforms, and on MySQL versions before 8.0.28, the limit is 2038-01-19 03:14:07 UTC instead. Divide milliseconds by 1000, and for dates before 1970 use DATE_ADD('1970-01-01', INTERVAL epoch SECOND).
MySQL

Need a MySQL GUI Client?

1bench is a modern database client for MySQL and 20+ other databases. Query, browse, and manage your data visually.

Learn More