DATE is a core ANSI-SQL data type for representing calendar dates independently of any clock time or time zone. A DATE value always contains three numeric parts—year, month, and day—formatted as YYYY-MM-DD in textual form. Internally, implementations often store DATE as an integer offset from a reference day, enabling efficient arithmetic (e.g., adding INTERVAL values).Key points:- Granularity is one day. Hours, minutes, seconds, and fractional seconds are not stored.- Time zone is never applied; DATE 2024-05-10 means the same calendar day everywhere.- Supported range varies by system (e.g., PostgreSQL 4713 BC to 5874897 AD; MySQL 1000-01-01 to 9999-12-31).- Standard SQL allows DATE literals using the keyword DATE followed by a string literal: DATE '2024-05-10'.- Conversions between DATE and TIMESTAMP types are allowed with CAST or implicit rules; the time portion defaults to 00:00:00 when casting DATE to TIMESTAMP.Practical uses include recording birthdays, hire dates, invoice due dates, or any fact that does not need a time component. Because DATE values are smaller than TIMESTAMPs, they save storage and avoid unwanted time zone shifts during serialization or display.Caveats:- Adding or subtracting INTERVAL values must honor calendar rules (leap years, month lengths).- String literals must be in the configured date style or use the ANSI form above to avoid localization problems.- DATE is a reserved keyword in most dialects; aliasing a table or column as DATE without quoting will error.
SQL-92 standard
DATE is used for values that need only a calendar day, such as birthdays, due dates, or historical events, without time or timezone complications.
The ANSI standard does not fix a range, but common implementations span 0001-01-01 to 9999-12-31 (MySQL) or wider (PostgreSQL 4713 BC to 5874897 AD).
Use CAST(ts AS DATE) or database-specific shorthand (e.g., ts::date in PostgreSQL). The time portion is truncated.
When a DATE is cast to TIMESTAMP, databases supply a default time of 00:00:00 because DATE contains no time information.