Gollapalli
Gollapalli

Reputation: 20

How to get the records based on between two years

I am saving the reporting date as date format (ex 2017-04-05) now I want the records only between two years based on reporting date, I am giving the from year and two year as 2016 and 2017

See My table structure

report_id | report_date | user_id | amount

1 | 2015-11-12 | 12 | 5000

2 | 2016-12-01 | 17 | 5000

3 | 2017-01-12 | 21 | 5000

4 | 2017-02-12 | 07 | 5000

The above table is my table structure

Now I want to get the records where report_date between year 2016 and 2017, I will not give complete date only I will give the year.

Upvotes: 0

Views: 1267

Answers (1)

Shogunivar
Shogunivar

Reputation: 1222

You can use YEAR() to get just the year of a date, then you can search between years like so:

SELECT *
FROM reports
WHERE YEAR(report_date) BETWEEN 2015 AND 2016; 

Upvotes: 3

Related Questions