pyspark.sql.functions.next_day#

pyspark.sql.functions.next_day(date, dayOfWeek)[source]#

Returns the first date which is later than the value of the date column based on second week day argument.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
dateColumn or column name

target column to compute on. A column that evaluates to a date.

dayOfWeekliteral string

day of the week, case-insensitive, accepts: “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”. A column that evaluates to a string.

Returns:
Column

the column of computed results. Returns a column that evaluates to a date.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([('2015-07-27',)], ['dt'])
>>> df.select('*', sf.next_day(df.dt, 'Sun')).show()
+----------+-----------------+
|        dt|next_day(dt, Sun)|
+----------+-----------------+
|2015-07-27|       2015-08-02|
+----------+-----------------+
>>> df.select('*', sf.next_day('dt', 'Sat')).show()
+----------+-----------------+
|        dt|next_day(dt, Sat)|
+----------+-----------------+
|2015-07-27|       2015-08-01|
+----------+-----------------+