datepart1
The datepart1 function is used to calculate the value from the date that matches the specified time unit datepart.
Syntax
datepart1(string date,string datepart)
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| date | Yes | DATE or STRING | The start date. Formats:
|
| datepart | Yes | STRING | The time unit to return. The datepart parameter supports extended date formats: year, month or mon, day, and hour.
|
Return Values
Returns a value of type BIGINT.
- If date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
- If date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
- If the date value is NULL, NULL is returned.
- If the datepart value is NULL, NULL is returned.
Example Code
Returns 2023.
select datepart1(date '2023-08-14 17:00:00', 'yyyy');
Returns 2023.
select datepart1('2023-08-14 17:00:00', 'yyyy'); Returns 59.
select datepart1('2023-08-14 17:59:59', 'mi') Returns NULL.
select datepart1(date '2023-08-14', null);
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot