This function is used to calculate the difference between date1 and date2.
Similar function: datediff1. The datediff1 function is used to calculate the difference between date1 and date2 and return the difference in a specified datepart.
datediff(string date1, string date2)
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
date1 |
Yes |
DATE or STRING |
Minuend of the date difference between date1 and date2. The following formats are supported:
|
date2 |
Yes |
DATE or STRING |
Subtrahend of the date difference between date1 and date2. The following formats are supported:
|
The return value is of the BIGINT type.
The value 10 is returned.
select datediff('2023-06-30 00:00:00', '2023-06-20 00:00:00');
The value 11 is returned.
select datediff(date '2023-05-21', date '2023-05-10');
The value NULL is returned.
select datediff(date '2023-05-21', null);