In this guide, we will explain how to use the MySQL YEAR function with syntax and examples.
Description
The MySQL YEAR function returns the year portion of a date value.
Syntax
The syntax for the YEAR function in MySQL is:
YEAR( date_value )
Parameters or Arguments
date_value
A date or datetime value from which to extract the year.
Note
- The YEAR function returns a four-digit year (a number from 1000 to 9999) given a date value.
- See also the EXTRACT, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, and MICROSECOND functions.
Applies To
The YEAR function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some YEAR function examples and explore how to use the YEAR function.
For example:
mysql> SELECT YEAR('2014-01-28'); Result: 2014 mysql> SELECT YEAR('2014-01-28 15:21:05'); Result: 2014 mysql> SELECT YEAR('2013-10-15'); Result: 2013
This last YEAR example would display the year portion of the current system date (current system date is returned by the CURDATE function).
mysql> SELECT YEAR(CURDATE());
Next Topic : Click Here
Pingback: MySQL: WEEKDAY Function | Adglob Infosystem Pvt Ltd