MySQL DATETIME: Range, Storage, Precision, and TIMESTAMP Difference
MySQL DATETIME stores a calendar date and clock time without converting the stored value to or from the session time zone. Its supported range is 1000-01-01 00:00:00 through 9999-12-31 23:59:59 at whole-second precision.
Syntax and fractional seconds
DATETIME[(fsp)]
The optional fsp specifies 0–6 fractional-second digits. It defaults to 0 (whole seconds); DATETIME(3) stores milliseconds and DATETIME(6) supports microseconds.
In MySQL 5.6.4 and later, DATETIME uses 5 bytes plus 0–3 bytes for fractional seconds, not a fixed 8 bytes:
| Declaration | Storage |
|---|---|
DATETIME or DATETIME(0) |
5 bytes |
DATETIME(1) or DATETIME(2) |
6 bytes |
DATETIME(3) or DATETIME(4) |
7 bytes |
DATETIME(5) or DATETIME(6) |
8 bytes |
The older 8-byte storage format applies to tables created before MySQL 5.6.4. See the official MySQL storage requirements.
Example: save an event time
CREATE TABLE events (
event_id BIGINT PRIMARY KEY,
event_name VARCHAR(100) NOT NULL,
starts_at DATETIME(3) NOT NULL
);
INSERT INTO events (event_id, event_name, starts_at)
VALUES (1, 'New Year event', '2026-12-31 20:00:00.125');
SELECT event_id, starts_at
FROM events
WHERE starts_at >= '2026-12-31'
AND starts_at < '2027-01-01';
The query finds events starting on December 31, 2026, including values with fractional seconds. A half-open range (>= the start and < the next day) avoids excluding the last fraction of a second, as can happen with BETWEEN ... AND '23:59:59'. It does not find every event that overlaps the day; overlap queries must also consider the event’s end time.
DATETIME versus TIMESTAMP
A DATETIME column preserves the date/time fields as stored; changing the session time_zone does not shift the retrieved value. A TIMESTAMP column converts values from the session time zone to UTC for storage and back on retrieval. TIMESTAMP also has a much narrower supported range (approximately 1970–2038 in MySQL 8.4).
Use DATETIME for scheduled local wall-clock times when the intended time zone is tracked separately, and choose TIMESTAMP when its UTC conversion and supported range fit your application. Neither type stores an IANA time-zone name by itself.
For supported ranges, time-zone handling, and fractional seconds, see the official MySQL DATETIME and TIMESTAMP documentation and the MySQL data types overview.