DATE data type.
Overview
The
DATE type represents a calendar date, independent of a time zone.
Literal string interpretation
DATE literals follow the ISO 8601 format: YYYY-[M]M-[D]D.
YYYY: Four-digit year (0001-9999)[M]M: One or two digit month (01-12)[D]D: One or two digit day (01-31)
Functions and operators
Type conversions
TheDATE data type can be cast to and from types as follows:
To DATE
From DATE
Comparison operators
A
DATE value is also comparable with a TIMESTAMP or TIMESTAMPTZ value:
- The
DATEvalue is cast to theTIMESTAMPtype for comparison with aTIMESTAMPvalue. - The
DATEvalue is cast to theTIMESTAMPTZtype for comparison with aTIMESTAMPTZvalue.
Arithmetic operators
The+ operators described below come in commutative pairs:
Interval arithmetic
Arithmetic with intervals can be used to add or subtract a duration to or from a date. The result is of typeTIMESTAMP.
Example
Rows: 1Execution time: 9.42ms
Rows: 1Execution time: 5.88ms
Serialization and deserialization
Text, CSV, JSON
In the text, CSV, and JSON format, aDATE value is output as a YYYY-MM-DD string. Input is accepted in the literal format described above: YYYY-[M]M-[D]D.
Parquet
DATE maps to Parquet’s 32-bit signed integer DATE type, also representing the number of days before or after 1970-01-01.
Avro
DATE maps to Avro’s 32-bit signed integer DATE type, also representing the number of days before or after 1970-01-01.
ORC
DATE maps to ORC’s signed integer DATE type, also representing the number of days before or after 1970-01-01.