Function Reference

FROM_UNIXTIME

PostgreSQL equivalent:

Converts Unix time to a datetime.

MySQL 8.1
FROM_UNIXTIME(unix_timestamp[, format])
  • [ ]optional part
unix_timestamp
Number of seconds since 1970-01-01 00:00:00 UTC
INT
format
Format of the result, specifiers as in DATE_FORMAT
VARCHAROptional

Return value

A datetime in the session time zone, or a string with format; NULL for a negative number

Examples

Date from a number of seconds

MySQL 8.1
SELECT FROM_UNIXTIME(1717588800);
FROM_UNIXTIME(1717588800)
2024-06-05 12:00:00

Result in a custom format

MySQL 8.1
SELECT FROM_UNIXTIME(1717588800, '%d.%m.%Y %H:%i') AS formatted;
formatted
05.06.2024 12:00

Details

The result is shown in the session time zone, so the same number gives different times on servers with different settings. A fractional number gives a date with fractional seconds: FROM_UNIXTIME(1717588800.5). The reverse conversion is done by UNIX_TIMESTAMP.

See also