pyspark.sql.functions.date_add#

pyspark.sql.functions.date_add(start, days)[source]#

Returns the date that is days days after start. If days is a negative value then these amount of days will be deducted from start.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
startColumn or str

date column to work on.

daysColumn or str or int

how many days after the given date to calculate. Accepts negative value as well to calculate backwards in time.

Returns
Column

a date after/before given number of days.

Examples

>>> df = spark.createDataFrame([('2015-04-08', 2,)], ['dt', 'add'])
>>> df.select(date_add(df.dt, 1).alias('next_date')).collect()
[Row(next_date=datetime.date(2015, 4, 9))]
>>> df.select(date_add(df.dt, df.add.cast('integer')).alias('next_date')).collect()
[Row(next_date=datetime.date(2015, 4, 10))]
>>> df.select(date_add('dt', -1).alias('prev_date')).collect()
[Row(prev_date=datetime.date(2015, 4, 7))]