time_diff
Returns the difference between two times, measured in specified units.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.time_diff(unit=<unit>, start=<start>, end=<end>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The unit to truncate the time to. Supported units are: "HOUR", "MINUTE", "SECOND", "MILLISECOND", and "MICROSECOND". The unit is case-insensitive. |
|
| A starting time. |
|
| An ending time. |
Returns
pyspark.sql.Column: The difference between two times, in the specified units.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame(
[("HOUR", "13:08:15", "21:30:28")], ['unit', 'start', 'end']).withColumn("start",
dbf.col("start").cast("time")).withColumn("end", dbf.col("end").cast("time"))
df.select('*', dbf.time_diff('unit', 'start', 'end')).show()