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
Advertisement
Answer
You can make use of DATE_FORMAT()
.
Example
SELECT * FROM table WHERE DATE_FORMAT(date,'%m-%d') BETWEEN '04-01' AND '04-19'
Edit
SELECT * FROM table WHERE STR_TO_DATE(date, '%m-%d') BETWEEN '04-01' AND '04-19'