How to User the YEAR() Function in MySQL
In this tutorial, you will learn how to use the MySQL YEAR() function to extract the year portion of a given date.
Syntax of the MySQL YEAR() Function
The syntax of the YEAR() function is as follows:
YEAR() Function Examples
Example 1: Extract the year portion of a given date.
The following SQL query extracts the year part from 2019-05-01 and returns the year 2019:
Example 2: Extract the year part of the current date
The following SQL query extracts the year part from the current date and returns the year part:
For example, if the CURDATE() function returns 2019-09-01, the year part is 2019.
Note that CURDATE() is a function that returns the current date.
In this tutorial, you have learned how to use the YEAR() function in MySQL. YEAR() is a function that returns the year part of a given date. If you want to get the month part, use the MONTH() function, and you can use the DAY() function to extract the day.