YEAR is a date-part extraction function that outputs the calendar year (0000-9999) from a valid date or timestamp value. Most commercial databases expose YEAR() as a built-in scalar function, while the SQL standard recommends EXTRACT(YEAR FROM date_expr). Although implementation details vary, the function always returns an integer representing the Gregorian year in the session time zone (unless the column stores timezone-aware data). YEAR is deterministic, index-friendly, and cheap to compute because it involves no I/O beyond reading the date column. Beware of NULL inputs (returns NULL), two-digit year conversions in legacy MySQL modes, and reserved-word conflicts when using YEAR as a column alias without quoting.
date_expression
(DATE, DATETIME, TIMESTAMP) - Required. The value from which to extract the year.EXTRACT, DATE_PART, MONTH, DAY, DATENAME, DATE_TRUNC
SQL:2003 (EXTRACT), vendor-specific YEAR existed earlier in MySQL 3.23, SQL Server 2008
YEAR() is a vendor shortcut. EXTRACT(YEAR FROM date_expr) is the portable, ANSI-compliant form.
Yes, functional indexes allow YEAR(date_col). This speeds up queries that filter by year but may increase storage.
When the sql_mode is set to ALLOW_INVALID_DATES or NO_ZERO_DATE, MySQL interprets two-digit years using the 1970–2069 window. Cast to DATE with four digits to avoid surprises.
The function reads the stored value. In TIMESTAMP WITH TIME ZONE types, the engine converts the value to session time zone before extraction, potentially shifting the year at UTC boundaries.