MySQL provides several temporal data types. Choose the type by the information you need to store: a calendar date, a date with time, an elapsed time, an automatically converted timestamp, or a year.
Quick query: You can store dates without a time, or full date-and-time values.
SELECT DATE('2026-11-14 10:30:00') AS event_date,
CAST('2026-11-14 10:30:00' AS DATETIME) AS starts_at;
Expected output (example data)
| event_date | starts_at |
|---|---|
| 2026-11-14 | 2026-11-14 10:30:00 |
| Type | Typical format | Use |
|---|---|---|
DATE | YYYY-MM-DD | Calendar dates without a time component. |
DATETIME(fsp) | YYYY-MM-DD HH:MM:SS[.fraction] | Date and time values independent of session time-zone conversion. |
TIMESTAMP(fsp) | YYYY-MM-DD HH:MM:SS[.fraction] | Stored internally in UTC and converted using the session time zone; useful for event timestamps. |
TIME(fsp) | [-]HHH:MM:SS[.fraction] | Time of day or elapsed intervals; range is approximately -838:59:59 to 838:59:59. |
YEAR | YYYY | Year values; prefer YEAR, not deprecated display-width forms such as YEAR(4). |
CREATE TABLE event_schedule (
event_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
event_date DATE NOT NULL,
starts_at DATETIME,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
duration TIME,
event_year YEAR,
PRIMARY KEY (event_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DATE and DATETIME support a much wider calendar range than TIMESTAMP. In MySQL 8.4, TIMESTAMP is limited to the Unix-timestamp range ending in January 2038, so use DATETIME when you need dates outside that range.
After creating event_schedule with the SQL above, add one event. The created_at column uses a database-generated timestamp, so this INSERT omits it.
INSERT INTO event_schedule
(event_date, starts_at, duration, event_year)
VALUES
('2026-11-14', '2026-11-14 09:30:00', '01:15:00', 2026);
SELECT event_date, starts_at, duration, event_year
FROM event_schedule
ORDER BY event_id;
Expected data columns after the first INSERT
| event_date | starts_at | duration | event_year |
|---|---|---|---|
| 2026-11-14 | 2026-11-14 09:30:00 | 01:15:00 | 2026 |
DATETIME stores the calendar date and clock time as supplied, without session time-zone conversion. TIMESTAMP is converted between the connection's session time zone and UTC. If your application changes time zones, this difference matters. The usable ranges are different too; MySQL 8.4 TIMESTAMP has a 2038 limit.
Do not store dates in a free-form text column solely for display convenience. Use an appropriate temporal type and format them in queries or your application. Remember that TIME can represent durations longer than 24 hours; it is not exclusively a time-of-day value.
See inserting dates, formatting dates and the current date.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.