MySQL YEAR() Function Examples

MySQL YEAR() Function Examples

Here You will learn how to use MySQL YEAR() function with syntax and examples. Today we are going to discuss MySQL YEAR() function with various examples.

When we want to filter data year wise from MySQL queries that time we could use MySQL year() function.

For example, if you want to fetch current year data from a mysql database or you want to fetch last year’s data from MySQL database, in that case, you can use MySQL year() function. Here we will also take an example of how to get current year data and year wise data from MySQL database.

MySQL YEAR() Function

In MySQL, the YEAR() is used to return the “year” part of the given date. It will return value year like 2018,2019 etc.


The YEAR() function syntax is:


Here :

  • The argument is the date you want the YEAR to return.


Now we take an example to demonstrate.

SELECT YEAR('2020-06-18') AS 'Result';


| Result |
|   2020 |


SELECT YEAR('2022-10-18') AS 'Result';


| Result |
|  2022  |

Example-3 | Current Year Record

Next database example, we take an example of getting the current year data from the MySQL database.

 FROM employees 
 WHERE YEAR(created_at) = YEAR(NOW()) ORDER BY id DESC



Example-4 | Current Date/Time

Let’s take another example, extracting part of the YEAR part from the current date and time (which is now returned using the () function).



| NOW()               | YEAR(NOW())        |
| 2019-07-10 18:30:44 |         2019       |

Example-6 | CURDATE() Function

Let’s take another example of using CURDATE() function. Basically CURDATE() function returns only the date without time.



| CURDATE()  |    YEAR(CURDATE())    |
| 2019-05-15 |           2019        |

Example-7 | Year Wise Data

You want to fetch year-wise data. Use the below query for getting year-wise data from the mysql database table.

SELECT COUNT(id) as Count,YEAR(created_at) as Year
FROM employees
GROUP BY YEAR(created_at)
Year Wise Data


Here, you have learned how to use MySQL YEAR() function with various examples.

You may like

  1. LAST_DAY MySQL Function Examples
  2. MySQL CURRENT TIMESTAMP Function Examples
  3. Get month name from date in mysql
  4. mysql get first day of the current month
  5. mysql last day of previous month
  6. Get month number from month name in mysql
  7. mysql get day of week number from date
  8. Mysql Get Data Of Current Date, Week, Month, YEAR
  9. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

If you have any questions or thoughts to share, use the comment form below to reach us.


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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