[MySQL] Convert a date-time string to a Unix timestamp

Created on November 30, 2026

You can use UNIX_TIMESTAMP() to convert a date-time string to seconds since the Unix epoch. MySQL interprets the string in the current session's time zone. This example sets the session to UTC so the input and result are reproducible.

SET time_zone = '+00:00';
SELECT UNIX_TIMESTAMP('2023-01-05 00:00:00') AS unix_seconds;
1672876800

Reference

MySQL