MySQL Date and Time Data Types

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_datestarts_at
2026-11-142026-11-14 10:30:00
TypeTypical formatUse
DATEYYYY-MM-DDCalendar 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.
YEARYYYYYear values; prefer YEAR, not deprecated display-width forms such as YEAR(4).
On this page — Show page sectionsHide page sections

Example table

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.


Create Table DataType Numeric Copy Table & SHOW CREATE Table
Data Types

Insert and retrieve a date/time record

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_datestarts_atdurationevent_year
2026-11-142026-11-14 09:30:0001:15:002026

DATETIME vs TIMESTAMP: practical difference

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.

Common date/time mistakes

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.

Further examples

See inserting dates, formatting dates and the current date.

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer