MySQL YEAR() Function with Examples


How to Extract Year Part of a Given Date in MySQL

In this tutorial, you'll learn how to use the MySQL YEAR() function to extract the year part of a given date.

YEAR() Syntax

The syntax of the YEAR() function is as follows:

YEAR(date)

Examples

Example 1: Extract the Year Part of a Specified Date

The following statement extract the year part from 2019-05-01, and returns 2019:

SELECT YEAR("2019-05-01")

Example 2: Extract the Year Part of the Current Date

The following statement extracts the year part from the current date, and returns the year part:

SELECT YEAR(CURDATE());

For example, if the CURDATE() returns 2019-09-01, the year part is 2019.

Note that CURDATE() is a function to get the current date.

In this tutorial, you’ve learned how to use the MySQL YEAR() function. In MySQL, YEAR() is a function to get the year part of a given date. If you need to get the month part, use MONTH(), and use DAY() to extract the day part.

Leave a Reply

Your email address will not be published. Required fields are marked *