Function Reference

YEAR

PostgreSQL equivalent:

Returns the year of a date.

MySQL 8.1
YEAR(date)

Parameters

dateDATE
Date or datetime

Return value

An integer up to 9999, less than 1000 for early dates: YEAR('0500-01-01') = 500; NULL if the value is not recognized as a date

Examples

Year from a date

MySQL 8.1
SELECT YEAR('2022-06-16');
YEAR('2022-06-16')
2022

Year of birth

MySQL 8.1
SELECT member_name,
	YEAR(birthday) AS birth_year
FROM FamilyMembers;
member_namebirth_year
Headley Quincey1960
Flavia Quincey1963
Andie Quincey1983
Lela Quincey1985
Annie Quincey1988
Ernest Forrest1961
Constance Forrest1968
Wednesday Addams2005

Details

A condition on the year is better written as a date range: birthday < '1980-01-01' instead of YEAR(birthday) < 1980. The result is the same, but a function on the column prevents using an index.

See also

Where to learn