time_diff function
Applies to: Databricks SQL
Databricks Runtime 18 and above
remarque
Databricks Runtime 18 is newer than Databricks Runtime 18.0, 18.1, and 18.2. Features that would previously have shipped as a later numbered version now ship as dated updates to Databricks Runtime 18 instead. For details, see About unified release notes.
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