Md. Motiur Rahman Md. Motiur Rahman - 4 years ago 84
MySQL Question

sql get result of current year only

sql get result of current year

I have a table that has a column date with date in

formate yyyy-mm-dd

now I want to do select query that only return current year result

sudo code should be like

select * from table where date is (current year dates)

result should be as following

id date
2 2015-01-01
3 2015-02-01
9 2015-01-01
6 2015-02-01

how do I do this

Answer Source

Use YEAR() to get only the year of the dates you want to work with:

select * from table where YEAR(date) = YEAR(CURDATE())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download