Skip to content
Advertisement

SQL – Get result of current year only

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?

Advertisement

Answer

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

select * from table where YEAR(date) = YEAR(CURDATE())
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement