datediff1
The datediff1 function is used to calculate the difference between two times, date1 and date2, and expresses the difference in the specified time unit datepart.
Similar function: datediff. The datediff function calculates the date difference between two times, date1 and date2, and does not support specifying the return time unit.
Syntax
datediff1(string date1, string date2, string datepart)
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| date1 | Yes | DATE or STRING | The minuend in the date difference calculation between two times, date1 and date2. Formats:
|
| date2 | Yes | DATE or STRING | The subtrahend in the date difference calculation between two times, date1 and date2. 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 date1 or date2 is not of type DATE or STRING, an error is returned with the message "data type mismatch".
- If date1 or date2 is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
- If date1 is less than date2, the return value is negative.
- If the date1 or date2 value is NULL, NULL is returned.
- If the datepart value is NULL, NULL is returned.
Example Code
Returns 14400.
select datediff1('2023-06-30 00:00:00', '2023-06-20 00:00:00', 'mi'); Returns 10.
select datediff1(date '2023-06-21', date '2023-06-11', 'dd');
Returns NULL.
select datediff1(date '2023-05-21', date '2023-05-10', null);
Returns NULL.
select datediff1(date '2023-05-21', null, 'dd');
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