Reputation: 35
I have database with toners. I need to get result only from lastest spetember every year to currrent date.
SELECT * FROM used_toners WHERE date >= '01-09-2018' # but after september of 2019 I need date '01-09-2019' and so on
Upvotes: 2
Views: 587
Reputation: 1013
With this query I select all the ranges of dates from September of last year to September of this year.
SELECT *
FROM used_toners
WHERE (YEAR(`date`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))
AND MONTH(`date`) BETWEEN 9 AND 12)
OR (YEAR(`date`) = YEAR(CURRENT_DATE())
AND MONTH(`date`) BETWEEN 1 AND 9)
Here you can find MONTH()
and YEAR()
documentation.
Upvotes: 1
Reputation: 1271151
If you want data from all Septembers, you can use month()
or similar functions:
SELECT ut.*
FROM used_toners ut
WHERE MONTH(date) = 9;
Upvotes: 1