pyspark.sql.functions.year

pyspark.sql.functions.year(col: ColumnOrName) → pyspark.sql.column.Column

Extract the year of a given date as integer.

Examples

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