SQL - Get result of current year only
Using WHERE YEAR(date) = YEAR(CURDATE())
is correct but it cannot use an index on column date
if exists; if it doesn't exist it should.
A better solution is:
SELECT *
FROM tbl
WHERE `date` BETWEEN '2015-01-01' AND '2015-12-31'
The dates (first and last day of the year) need to be generated from the client code.
Use YEAR()
to get only the year of the dates you want to work with:
select * from table where YEAR(date) = YEAR(CURDATE())