Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Get result of current year only

Tags:

How can I get the result of the current year using SQL?

I have a table that has a column date with the format yyyy-mm-dd.

Now, I want to do select query that only returns the current year result.

The pseudo code should be like:

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

The result should be as following:

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

How can I do this?

like image 672
Md. Motiur Rahman Avatar asked Jan 02 '15 16:01

Md. Motiur Rahman


1 Answers

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

select * from table where YEAR(date) = YEAR(CURDATE()) 
like image 56
John Conde Avatar answered Sep 18 '22 14:09

John Conde