time_diff function
Applies to: Databricks SQL
Databricks Runtime 18.3 and above
Returns the difference between two time values measured in units.
Syntax
time_diff(unit, start, end)
unit
{ MICROSECOND |
MILLISECOND |
SECOND |
MINUTE |
HOUR }
Arguments
Returns
A BIGINT.
If start is greater than end the result is negative.
Examples
SQL
> SELECT time_diff(HOUR, TIME'08:00:00', TIME'21:30:00');
13
> SELECT time_diff(MINUTE, TIME'08:00:00', TIME'08:45:30');
45
> SELECT time_diff(SECOND, TIME'10:00:00', TIME'10:00:30');
30
-- Start is greater than end
> SELECT time_diff(HOUR, TIME'21:00:00', TIME'08:00:00');
-13