MySQL Year Function

MySQL Year function is one of the Date Functions, which returns the Year from the given date. This MySQL Year function returns value range from 1000 to 9999. The syntax of the Year() Function in MySQL is as shown below:

YEAR(date or expression);

MySQL Year function Example

The below shown queries helps you understand the basic use of Year function. Here, we are returning the Year value from the date expression, and the Date and time expression.

TIP: The Year Date Function returns 0 if the date argument is 0000-00-00 or say zero date part.

SELECT YEAR('2016-11-25');

SELECT YEAR('2018-10-22 01:09:22');
MYSQL Year Function 2

Let us see another example of the Year function. Here, we are extracting Year from the current date and time returned by the Now() function.

MYSQL Year Function 3

Year Function Example 2

The following query show what happens when we try to extract the year from a date or date and time in string format.

SELECT YEAR('2016-11-44');


MYSQL Year Function 4

From the above screenshot, YEAR(‘2016-11-44’); is returning NULL because it is an invalid date. Last statement YEAR(0) means we are trying to extract Year from a zero date part. That’s why MySQL returns NULL.