pyspark.sql.functions.dayofweek#

pyspark.sql.functions.dayofweek(col)[source]#

Extract the day of the week of a given date/timestamp as integer. Ranges from 1 for a Sunday through to 7 for a Saturday

New in version 2.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target date/timestamp column to work on.

Returns
Column

day of the week for given date/timestamp as integer.

Examples

>>> df = spark.createDataFrame([('2015-04-08',)], ['dt'])
>>> df.select(dayofweek('dt').alias('day')).collect()
[Row(day=4)]