SELECT id, YEAR(publish_date) AS publishYear FROM article WHERE YEAR(publish_date) = 2021;
In some cases, you only want to use the year part of a
DATETIME field. In this case, simply use the built-in
YEAR() function with the relevant field as the parameter.
YEAR() function returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.