I am trying to filter out certain dates in my query. The line of code I am using in my query is as follows:
(date(date_add(date_time,-1,'year')) < date(date_add(current_date(),-1,'year')) ) OR year(date_time) = 2017)
The idea is to get all data YTD in 2017, as well as the data from 2016 that corresponds to those same days. So if I were to run a proper version of what I want, it would return all data YTD, as well as all 2016 data up until Nov. 16, 2016.
However, whenever I run the query with this in the WHERE clause, my query still returns dates that do not fit within my described parameters. I may be missing something completely obvious but this has been driving me nuts. Is there a particular way to filter dates that I'm missing?
Edit: Here is some of my data
[date] [today] [uniques]
2016-01-01 2017-11-16 363878
2016-01-02 2017-11-16 383813
2016-01-03 2017-11-16 392579
2016-01-04 2017-11-16 709367
..
..
2016-11-15 2017-11-16 841850
2016-11-16 2017-11-16 847831
2016-11-17 2017-11-16 797610
2016-11-18 2017-11-16 187158
2016-11-19 2017-11-16 521100
..
2017-11-12 2017-11-16 297604
2017-11-13 2017-11-16 527858
2017-11-14 2017-11-16 474051
2017-11-15 2017-11-16 569686
I added the today row for myself to make sure there wasn't a difference in date formatting. With this data, the bottom 3 rows in the middle section should not be returned, but they are. Everything else should fit the parameters I've set and get returned.
Appreciate any and all help. Thanks!