Forum Moderators: open
SELECT <fields here> WHERE DATE_FORMAT(field_date, '%m%Y') >= '042006' AND DATE_FORMAT(field_date, '%m%Y') <= '012007'
It produces no results. On the otherhand if I do
SELECT <fields here> WHERE DATE_FORMAT(field_date, '%m%Y') >= '042006' AND DATE_FORMAT(field_date, '%m%Y') <= '052007'
this does produce results - but only for between 042006 and 052006. In other words the year part of my query seems to be being ignored. Am using MySQL 5.0.20a.
I don't know MySQL, but something along the following should work:
SELECT <fields here>
WHERE field_date BETWEEN '4/1/2006' AND '1/1/2007'
SELECT <fields here> WHERE field_date BETWEEN '20060401' AND '20070101'
Comparing dates doesnt work if you leave out the day (I had just '%m%Y' originally). Im actually comparing two dates that are just months and years, so i need to manually stick the day on the ends of both dates im checking and it works great.