I have a table that holds items with a created_at DATETIME type column. I would like to return all items that were made in 2013.
I think I could do:
SELECT * FROM `items`
WHERE `created_at` > '2012' AND `created_at` < '2014'
But I would ideally like to be able to do something like:
SELECT * FROM `items`
WHERE `created_at` = '2013'
I think this fails because it looks for items with a DATETIME of 2013-01-01 00:00:00. Is there a way to do it by converting the MySQL created_at to a year when comparing?
Use
yearfunction forcreated_atcolumn