Nóta
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
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
from pyspark.sql import functions as dbf
dbf.add_months(start=<start>, months=<months>)
Parameters
| Parameter | Type | Description |
|---|---|---|
start |
pyspark.sql.Column or str |
date column to work on. |
months |
pyspark.sql.Column or str or int |
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
from pyspark.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()