Share via


date_add

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.

For the corresponding Databricks SQL function, see date_add (days) function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.date_add(start=<start>, days=<days>)

Parameters

Parameter Type Description
start pyspark.sql.Column or str date column to work on.
days pyspark.sql.Column or str or int how many days after the given date to calculate. Accepts negative value as well to calculate backwards in time.

Returns

pyspark.sql.Column: a date after/before given number of days.

Examples

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08', 2,)], 'struct<dt:string,a:int>')
df.select('*', dbf.date_add(df.dt, 1)).show()
df.select('*', dbf.date_add('dt', 'a')).show()
df.select('*', dbf.date_add('dt', dbf.lit(-1))).show()