pyspark.sql.functions.date_diff

pyspark.sql.functions.date_diff(end: ColumnOrName, start: ColumnOrName) → pyspark.sql.column.Column[source]

Returns the number of days from start to end.

New in version 3.5.0.

Parameters
endColumn or str

to date column to work on.

startColumn or str

from date column to work on.

Returns
Column

difference in days between two dates.

Examples

>>> df = spark.createDataFrame([('2015-04-08','2015-05-10')], ['d1', 'd2'])
>>> df.select(date_diff(df.d2, df.d1).alias('diff')).collect()
[Row(diff=32)]