mysql query and order by current month
mysql
Solution
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 BY` being out of place, you must compare both the month and the date. Since the function `MONTH()` 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 both `MONTH(), YEAR()` to compare months for the current year.
SELECT * FROM postdata
WHERE
MONTH(postdate) = MONTH(CURDATE())
AND YEAR(postdate) = YEAR(CURDATE())
ORDER BY postdate DESC
Problem
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?