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 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 function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.dateadd(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.dateadd(df.dt, 1)).show()
df.select('*', dbf.dateadd('dt', 'a')).show()
df.select('*', dbf.dateadd('dt', dbf.lit(-1))).show()