date_sub
Returns the date that is days days before start. If days is a negative value then these amount of days will be added to start.
For the corresponding Databricks SQL function, see date_sub function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.date_sub(start=<start>, days=<days>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| date column to work on. |
|
| how many days before the given date to calculate. Accepts negative value as well to calculate forward in time. |
Returns
pyspark.sql.Column: a date before/after given number of days.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08', 2,)], 'struct<dt:string,a:int>')
df.select('*', dbf.date_sub(df.dt, 1)).show()
df.select('*', dbf.date_sub('dt', 'a')).show()
df.select('*', dbf.date_sub('dt', dbf.lit(-1))).show()