Question

I have a custom php/sql application that tracks inquires by day and displays the daily total for the past 31 days.

For some reason, the ORDER BY date DESC will not pull anything after Feb 28th. - Yes the date column is in the correct MySQL date type format. All inserted entries have the correct date, so I know it's not the data within the table.

Here is my query:

SELECT date, date_format(date, '%W, %M %e') AS day, COUNT('day') AS daycount 
FROM inquiries 
GROUP BY day 
ORDER BY date DESC LIMIT 31

I cant seem to figure out why the descending order shows that Feb 28th is the most recent day, when in fact it is March 3rd. If I go into phpmyadmin and order by the date column desc, it sorts exactly like expected with March 3rd at the top. Anyone have an idea? Thanks in advance.

No correct solution

OTHER TIPS

Simply changing GROUP BY day to GROUP BY date solved the problem...

No clue why it decided to break after Feb 28 though. I guess the date_format(date, '%W, %M %e') AS day gets messed up after a leap year day when sorting by the alias.

Would love to know why if anyone has any ideas. Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top