pyspark.sql.functions.add_months

pyspark.sql.functions.add_months(start: ColumnOrName, months: Union[ColumnOrName, int]) → pyspark.sql.column.Column

Returns the date that is months months after start

Examples

>>> df = spark.createDataFrame([('2015-04-08', 2)], ['dt', 'add'])
>>> df.select(add_months(df.dt, 1).alias('next_month')).collect()
[Row(next_month=datetime.date(2015, 5, 8))]
>>> df.select(add_months(df.dt, df.add.cast('integer')).alias('next_month')).collect()
[Row(next_month=datetime.date(2015, 6, 8))]