MySQL Query to Get Current Year Data Example

By Hardik Savani June 6, 2023 Category : MySql

If you require to get all the records of current year using mysql query. for example you have one table "items" and columns are id, title, description, created_at and update_at, Now you want to get all records of this year. so you can fetch fields value using DATE_SUB and INTERVAL of mysql. In following example you can see how to select data of current year.

Example:

SELECT * FROM items WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 YEAR);

I hope it can help you...

Tags :
Shares