I have a query that looks like this: $latest = mysql_query("SELECT id, DATE_FORMAT(`date`, '%d-%m-%Y') AS date, name, suburb, source, rating, salesperson FROM lead ORDER BY date DESC LIMIT 10;") or die(mysql_error()); Code (markup): Which works perfect, BUT it's not sorting the results by date correctly. It's only sorting by DAY. This wouldn't be a problem if I just sort by the mysql datefield.. but I live in Australia and we use date,month,year not the standard year,day,month..
after a heap of googling... it turns out you can only sort by largest to smallest.. So I had to work around it by doing this: $latest = mysql_query("SELECT id, date AS datesort, DATE_FORMAT(`date`, '%d-%m-%Y') AS date, name, suburb, source, rating, salesperson FROM lead ORDER BY datesort DESC LIMIT 10;") or die(mysql_error()); Kind sucks.. but works. Maybe someone can tell me a better way without storing day, month, year in separate columns. meh
You should be able to format the date column separately and still sort by the original values. Is the column an actual date column or are the dates being stored in a char or varchar?