I am trying to select records that have the curent month using:
SELECT * FROM postdata
ORDER BY postdate DESC
WHERE MONTH(postdate) = MONTH(CURRENT_DATE)
The date format for postdate is YYYY-MM-DD (2012-06-30 for example), but unfortunately no records are being returned. Is this the corrent MySQL statement to use?
It isn’t fully clear that this is your intent, but it seems likely so I’ll contribute as an answer:
Aside from your
ORDER BYbeing out of place, you must compare both the month and the date. Since the functionMONTH()returns only a number 1 through 12, the query would return all records for June of all years, rather than only the current year. Use bothMONTH(), YEAR()to compare months for the current year.