Monday, 26 August 2013

MySQL: Query to check if date is between two month-day values

MySQL: Query to check if date is between two month-day values

I want to know if a date (Year-Month-Day) is between a day of the month
(Month-Day).
For example, I want to know if 'April 2, 2013' is between 'April 2' and
'April 19'.
I can easily do this of the range has a year value. Howver, without a
year, I need ideas how to do this.
Some examples of what I'm trying to achieve:
SELECT 1 WHERE '2013-04-02' BETWEEN '04-01' AND '04-19'; -- result is 1
SELECT 1 WHERE '2014-04-02' BETWEEN '04-01' AND '04-19'; -- result is 1
SELECT 1 WHERE '2014-03-02' BETWEEN '04-01' AND '04-19'; -- result is 1
Thanks

No comments:

Post a Comment