- Instant help with your Sql coding problems

Extract year from a date in MySQL

Question:
How to extract year from a date in MySQL?
Answer:
SELECT id, YEAR(publish_date) AS publishYear 
FROM article WHERE YEAR(publish_date) = 2021;
Description:

In some cases, you only want to use the year part of a DATE or DATETIME field. In this case, simply use the built-in YEAR() function with the relevant field as the parameter.

The YEAR() function returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.

Reference:
YEAR reference
Share "How to extract year from a date in MySQL?"