pyspark.sql.functions.year#
- pyspark.sql.functions.year(col)[source]#
Extract the year of a given date/timestamp as integer.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or str target date/timestamp column to work on.
- col
- Returns
Column
year part of the date/timestamp as integer.
Examples
>>> df = spark.createDataFrame([('2015-04-08',)], ['dt']) >>> df.select(year('dt').alias('year')).collect() [Row(year=2015)]