Set the session time zone
MySQL conversion functions depend on the session time zone. In this example, the session is set to UTC.
SET time_zone = '+00:00';
SELECT FROM_UNIXTIME(1711972800);
-- 2024-04-01 12:00:00
SELECT UNIX_TIMESTAMP('2024-04-01 12:00:00');
-- 1711972800TIMESTAMP or DATETIME?
MySQL converts TIMESTAMP values between the session time zone and UTC when storing and reading them. DATETIME stores calendar fields without this automatic conversion. Neither type alone stores a time zone name such as Europe/Paris.
CREATE TABLE events (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
occurred_at TIMESTAMP(6) NOT NULL
);
INSERT INTO events (occurred_at)
VALUES ('2024-04-01 12:00:00.123456');Check the range and precision
In MySQL 8.4, TIMESTAMP is still limited to a range from 1970 to January 2038. DATETIME has a different range. Check the documentation for your version before choosing a type for birth dates or distant deadlines.
Fractions must be specified in the column definition, for example TIMESTAMP(6). Local conversions around clock changes can be ambiguous; exchange instants in UTC where possible.
References
English version published September 26, 2026.