Categories: Date/Time
DATE_TRUNC
Truncates a DATE or TIMESTAMP to the specified precision. Returns NULL if any input is NULL.
Syntax
DATE_TRUNC(time_unit LITERAL, date_timestamp_expression DATE OR TIMESTAMP) → DATE
- time_unit: The time unit that the date or timestamp needs to be truncated at. This must be the literal value of 'YEAR', 'QUARTER', 'MONTH', 'WEEK', 'DAY', 'DECADE', 'CENTURY', or 'MILLENNIUM'. For a timestamp, 'HOUR', 'MINUTE', and 'SECOND' are also valid.
- date_timestamp_expression: The date or timestamp to truncate. This value must be a literal in the date or timestamp format.
Examples
DATE_TRUNC exampleSELECT DATE_TRUNC('MONTH', '2021-12-24')
-- 2021-12-01
SELECT DATE_TRUNC('MINUTE', CAST('2021-12-24 12:28:33' as TIMESTAMP))
-- 2021-12-24 12:28:00
SELECT DATE_TRUNC('HOUR', '2021-12-24 12:28:33')
-- 2021-12-24
SELECT DATE_TRUNC('YEAR', DATE '2026-03-18')
-- 2026-01-01
SELECT DATE_TRUNC('YEAR', TIMESTAMP '2026-03-18 14:30:45')
-- 2026-01-01 00:00:00
SELECT DATE_TRUNC('HOUR', TIMESTAMP '2026-03-18 14:30:45')
-- 2026-03-18 14:00:00