Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Returns the difference between two times, measured in specified units.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.time_diff(unit=<unit>, start=<start>, end=<end>)
Parameters
| Parameter | Type | Description |
|---|---|---|
unit |
pyspark.sql.Column or str |
The unit to truncate the time to. Supported units are: "HOUR", "MINUTE", "SECOND", "MILLISECOND", and "MICROSECOND". The unit is case-insensitive. |
start |
pyspark.sql.Column or str |
A starting time. |
end |
pyspark.sql.Column or str |
An ending time. |
Returns
pyspark.sql.Column: The difference between two times, in the specified units.
Examples
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()