What's the best (fastest) approach to compare if date is in range of dates independently from year?
table "dates":
some_column| since | upto |
-----------|--------------|-------------|
'foo' | '2011-05-01' | '2013-06-01'|
Now I want this query to return 'foo'
SELECT foo FROM dates WHERE '2014-05-05' BETWEEN `since` AND `upto`
If needed, I can change type/format of stored dates in "dates" table, but I cannot change format of date which I put into query as that value is typically from another table (It's part of more complex query using joins).
Use the DayOfYear function:
SELECT foo FROM dates WHERE DayOfYear('2014-05-05')
BETWEEN DayOfYear(`since`) AND DayOfYear(`upto`)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With