DATE_PART
functionsupportedCore SQL functionsExtracts the specified date or time part from a date, time, or timestamp.
Syntax
DATE_PART( <date_or_time_part> , <date_interval_time_or_timestamp_expr> )
DATE_PART( <date_or_time_part> FROM <date_interval_time_or_timestamp_expr> )
Parameters
| Name | Required | Description |
|---|---|---|
date_or_time_part | required | The unit of time. Must be one of the values listed in Supported date and time parts (for example, month). The value can be a string literal or can be unquoted (for example, 'month' or month). When date_or_time_part is week (or any of its variations), the output is controlled by the WEEK_START session parameter. When date_or_time_part is dayofweek or yearofweek (or any of their variations), the output is controlled by the WEEK_OF_YEAR_POLICY and WEEK_START session parameters. For more information, including examples, see Calendar weeks and weekdays. |
date_interval_time_or_timestamp_expr | required | A date, an interval, a time, or a timestamp, or an expression that can be evaluated to one of those data types. |
Returns
Returns a value of NUMBER data type.
Usage notes
- When date_interval_time_or_timestamp_expr is a year-month interval value, the supported date_or_time_part values are year and month.
- When date_interval_time_or_timestamp_expr is a day-time interval value, the supported date_or_time_part values are day, hour, minute, second, and nanosecond.
- Currently, when date_interval_time_or_timestamp_expr is a DATE value, the following date_or_time_part values aren’t supported: epoch_millisecond
- epoch_microsecond
- epoch_nanosecond
- Other date and time parts (including epoch_second) are supported.
- Tip
- To extract a full DATE or TIME value instead of a single part from a TIMESTAMP value, you can cast the TIMESTAMP value to a DATE or TIME value, respectively. For example: