pyspark.sql.functions.weekofyear#

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

Extract the week number of a given date as integer. A week is considered to start on a Monday and week 1 is the first week with more than 3 days, as defined by ISO 8601

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target timestamp column to work on.

Returns
Column

week of the year for given date as integer.

Examples

>>> df = spark.createDataFrame([('2015-04-08',)], ['dt'])
>>> df.select(weekofyear(df.dt).alias('week')).collect()
[Row(week=15)]