How do we extract the 4-digit calendar year integer from an order date Column?
year() extracts the calendar year component as an IntegerType from a date or timestamp Column.
Creating annual partition directories in lakehouses and grouping financial transactions by year.
from pyspark.sql.functions import col, year
df = df.withColumn("order_year", year(col("order_date")))Practice typing production-grade PySpark code for Extracting Calendar Year with year().