add_months
Returns the date that is months months after start. If months is a negative value then these amount of months will be deducted from the start.
For the corresponding Databricks SQL function, see add_months function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.add_months(start=<start>, months=<months>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| date column to work on. |
|
| how many months after the given date to calculate. Accepts negative value as well to calculate backwards. |
Returns
pyspark.sql.Column: a date after/before given number of months.
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.add_months(df.dt, 1)).show()
df.select('*', dbf.add_months('dt', 'a')).show()
df.select('*', dbf.add_months('dt', dbf.lit(-1))).show()