Reputation: 345
How do you get the current year (as a four digit number) for use in a MySql WHERE
clause?
I have the following query:
SELECT * FROM tblfeatured WHERE yeargrad LIKE date('Y')
The yeargrad
columns stores just a year (e.g 2017) and I would like to find rows where this matches the current year.
Upvotes: 19
Views: 42234
Reputation: 22941
For completeness sake, please note you can also use DATE_FORMAT()
DATE_FORMAT(NOW(), '%Y')
or
DATE_FORMAT(CURDATE(), '%Y')
Upvotes: 3
Reputation: 328
SELECT * FROM tblfeatured WHERE YEAR(yeargrad) = YEAR(CURRENT_DATE())
Upvotes: 5
Reputation: 39497
You can use curdate()
function to get today's date and then use year()
function on it to get the current year.
SELECT * FROM tblfeatured WHERE yeargrad = year(curdate());
Upvotes: 29