MySQL YEAR() Function

The YEAR() function in MySQL extracts the year from a date or datetime value. This is a very useful function for working with dates and performing year-based analysis or filtering.



YEAR(): Definition and Usage

The YEAR() function takes a date or datetime value as input and returns the year as a four-digit integer (between 1000 and 9999). It's commonly used to filter data based on specific years, to group data by year, or to perform year-related calculations within your MySQL queries.

Syntax

Syntax

YEAR(date)
      

Parameter Values

Parameter Description
date The date or datetime value from which to extract the year. This is required.

Examples

Extracting the Year from a DATE Value

This example extracts the year from the date '2017-06-15'.

Syntax

SELECT YEAR("2017-06-15");
      
Output

2017
      

Extracting the Year from a DATETIME Value

This example demonstrates that YEAR() correctly handles datetime values; it ignores the time part and returns only the year.

Syntax

SELECT YEAR("2017-06-15 09:34:21");
      
Output

2017
      

Extracting the Current Year

This example gets the current year from the system.

Syntax

SELECT YEAR(CURDATE());
      
Output

(The current year will be displayed here.)
      

**Note:** The output of the last example will be the current year according to your MySQL server's system clock. The year will be a four-digit integer.