DATE_TRUNC
functionsupportedCore SQL functionsTruncates a DATE, TIME, or TIMESTAMP value to the specified precision. For example, truncating a timestamp down to the quarter returns the timestamp corresponding to midnight of the first day of the original timestamp’s quarter. This function provides an alternative syntax for TRUNCATE, TRUNC by reversing the two arguments. Truncation is not the same as extraction. For example: - Truncating a timestamp down to the quarter using this function returns the timestamp corresponding to midnight of the first day of the quarter for the input timestamp. - Extracting the quarter date part from a timestamp using the Extract function returns the quarter number of the year in the timestamp.
Syntax
DATE_TRUNC( <date_or_time_part>, <date_or_time_expr> )
Parameters
| Name | Required | Description |
|---|---|---|
date_or_time_part | required | This argument must be one of the values listed in Supported date and time parts. |
date_or_time_expr | required | This argument must evaluate to a date, time, or timestamp. |
Returns
The returned value is the same type as the input value. For example, if the input value is a TIMESTAMP, then the returned value is a TIMESTAMP.
Usage notes
- When date_or_time_part is week (or any of its variations), the output is controlled by the WEEK_START session parameter. For more details, including examples, see Calendar weeks and weekdays.
- For TIME values, you can’t specify a date_or_time_part that is outside the scope of the TIME type. For example, you can truncate a TIMESTAMP value to a day, week, year, and so on because the TIMESTAMP type encodes date/times with the required precision. However, trying to truncate a TIME value to a day, week, year, and so on causes an error.