Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.13 KB

File metadata and controls

35 lines (27 loc) · 1.13 KB
description
Truncates the date or timestamp to the indicated precision.

DATE_TRUNC

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’, ‘MONTH’, ‘DAY’, ‘HOUR’, ‘MINUTE’, or ‘SECOND’.
  • date_timestamp_expression: The date or timestamp to truncate. This value must be a literal in the date or timestamp format.

Examples

{% code title="DATE_TRUNC example" %}

SELECT DATE_TRUNC('MONTH', '2021-12-24')
-- 2021-12-01

{% endcode %}

{% code title="DATE_TRUNC example" %}

SELECT DATE_TRUNC('MINUTE', CAST('2021-12-24 12:28:33' as TIMESTAMP))
-- 2021-12-24 12:28:00

{% endcode %}

{% code title="DATE_TRUNC example" %}

SELECT DATE_TRUNC('HOUR', '2021-12-24 12:28:33')
-- 2021-12-24

{% endcode %}