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 of birth
MySQL 8.1
SELECT member_name,
YEAR(birthday) AS birth_year
FROM FamilyMembers;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.