MySQL date format DD/MM/YYYY select query?

basickarl picture basickarl · May 17, 2012 · Viewed 828.4k times · Source

I'm a bit confused on how to order by date formats.

For the format YYYY-MM-DD you would do this: ...ORDER BY date DESC...

How would you order by DD/MM/YYYY?

This isn't working:

SELECT * FROM $table ORDER BY DATE_FORMAT(Date, '%Y%m%d') DESC LIMIT 14

Answer

trapper picture trapper · May 17, 2012

Guessing you probably just want to format the output date? then this is what you are after

SELECT *, DATE_FORMAT(date,'%d/%m/%Y') AS niceDate 
FROM table 
ORDER BY date DESC 
LIMIT 0,14

Or do you actually want to sort by Day before Month before Year?