pyspark.sql.functions.dateadd#
- pyspark.sql.functions.dateadd(start, days)[source]#
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.
New in version 3.5.0.
- Parameters
- Returns
Column
a date after/before given number of days.
See also
Examples
>>> import pyspark.sql.functions as sf >>> df = spark.createDataFrame([('2015-04-08', 2,)], 'struct<dt:string,a:int>') >>> df.select('*', sf.dateadd(df.dt, 1)).show() +----------+---+---------------+ | dt| a|date_add(dt, 1)| +----------+---+---------------+ |2015-04-08| 2| 2015-04-09| +----------+---+---------------+
>>> df.select('*', sf.dateadd('dt', 'a')).show() +----------+---+---------------+ | dt| a|date_add(dt, a)| +----------+---+---------------+ |2015-04-08| 2| 2015-04-10| +----------+---+---------------+
>>> df.select('*', sf.dateadd('dt', sf.lit(-1))).show() +----------+---+----------------+ | dt| a|date_add(dt, -1)| +----------+---+----------------+ |2015-04-08| 2| 2015-04-07| +----------+---+----------------+