dateadd
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 dateadd (timestamp) function.
Syntax
Python
from pyspark.sql import functions as dbf
dbf.dateadd(start=<start>, days=<days>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| date column to work on. |
|
| 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
Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08', 2,)], 'struct<dt:string,a:int>')
df.select('*', dbf.dateadd(df.dt, 1)).show()
df.select('*', dbf.dateadd('dt', 'a')).show()
df.select('*', dbf.dateadd('dt', dbf.lit(-1))).show()