MySQL Year is one of the Date Functions, which returns the Year from the given date. This Year function returns values ranging from 1000 to 9999, and its syntax is shown below:
YEAR(date or expression);
MySQL Year function Example
The below-shown queries help you understand the basic use of the MySQL Year function. Here, we are returning the Year value from the date expression and the DateTime expression.
TIP: This Date method returns 0 if the date argument is 0000-00-00 or, say, zero datepart.
SELECT YEAR('2018-10-22 01:09:22');
Let us see another example of this method, and here, we are extracting Year from the current datetime returned by the Now().
The following query show what happens when we try to extract the year from a date or datetime in string format.
SELECT YEAR(NOW() + 5);
From the above screenshot, (‘2016-11-44’); is returning NULL because it is an invalid one. The last statement (0) means we are trying to extract Year from a zero datepart. That’s why MySQL returns NULL.