Discussion: ordering dates
Afficher un message
Vieux 12/09/2007, 22h12   #4
Philip Hallstrom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ordering dates

> $result= mysql_query("SELECT date_format(date, '%d/%m/%Y') as date, title,
> id, display FROM news ORDER BY date DESC ");
>
> I have the query above the problem is oders them like so
>
> 30/05/2007
> 29/07/2007
> 25/0/2007
>
>
> The order is taken by the first number. Is there any way to order them
> properly without a timestamp?


You're ordering by "date" but previously you turn "date" into a string by
calling date_format on it. Change the "as date" to something else and
then the ordering will be chronologically descending. Like this:

SELECT date_format(date, '%d/%m/%Y') as formatted_date, title, id, display
FROM news ORDER BY date DESC

  Réponse avec citation
 
Page generated in 0,04170 seconds with 9 queries