This function is used to calculate the difference between date1 and date2 and return the difference in a specified datepart.
Similar function: datediff. The datediff function is used to calculate the difference between date1 and date2 but does not return the difference in a specified datepart.
datediff1(string date1, string date2, string datepart)
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:
|
datepart |
Yes |
STRING |
Unit of the time to be returned This parameter supports the following extended date formats: year, month or mon, day, and hour.
|
The return value is of the BIGINT type.
The value 14400 is returned.
select datediff1('2023-06-30 00:00:00', '2023-06-20 00:00:00', 'mi');
The value 10 is returned.
select datediff1(date '2023-06-21', date '2023-06-11', 'dd');
The value NULL is returned.
select datediff1(date '2023-05-21', date '2023-05-10', null);
The value NULL is returned.
select datediff1(date '2023-05-21', null, 'dd');