YEAR() in MySQL — How It Works
What the MySQL YEAR() function does, with an example.
Published October 20, 2026
YEAR(date) returns the year part of a date as a number (1000–9999).
How it works
Use it for grouping by year, but filter with ranges to keep indexes usable.
Try it in MySQL
SELECT YEAR('2026-11-12')
2026
SELECT YEAR(created_at), COUNT(*) FROM orders GROUP BY 1
per-year counts
SELECT YEAR(NOW()) - 1990
age-style maths
Practical examples
Example 1
SELECT YEAR('2026-11-12');
-- 2026Example 2
SELECT YEAR(created_at), COUNT(*) FROM orders GROUP BY 1;
-- per-year countsExample 3
SELECT YEAR(NOW()) - 1990;
-- age-style mathsUse it in a real query
SELECT id, YEAR('2026-11-12') AS result
FROM your_table
LIMIT 10;Common mistakes
- WHERE YEAR(col) = 2026 not using the index (use a date range).
- Passing non-dates.
- Zero dates.
Key takeaways
- YEAR() in one line: YEAR(date) returns the year part of a date as a number (1000–9999).
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
Index-friendly filter?
WHERE col >= '2026-01-01' AND col < '2027-01-01'.
Does YEAR() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.