PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > ordering dates
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
ordering dates

Réponse
 
LinkBack Outils de la discussion
Vieux 12/09/2007, 21h49   #1
Ross Hulford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?


Ta,

R.


  Réponse avec citation
Vieux 12/09/2007, 21h54   #2
Michael Dykman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ordering dates

May I suggest:

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

changing the alias of your formatted date to mydate, the raw value of
date is now available to order by.

- michael dykman


On 9/12/07, Ross Hulford <ross@aztechost.com> wrote:
> $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?
>
>
> Ta,
>
> R.
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=mdykman@gmail.com
>
>



--
- michael dykman
- mdykman@gmail.com

- All models are wrong. Some models are useful.
  Réponse avec citation
Vieux 12/09/2007, 21h56   #3
Jerry Schwartz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: ordering dates

I suspect that your problem is that you are converting your date field to a
string before sorting. You shouldn't use the same name for the alias as you
do for the field. Try

$result= mysql_query("SELECT date_format(date, '%d/%m/%Y') as
formatted_date, title,
id, display FROM news ORDER BY date DESC ");

Regards,

Jerry Schwartz
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341

www.the-infoshop.com
www.giiexpress.com
www.etudes-marche.com


> -----Original Message-----
> From: Ross Hulford [mailto:ross@aztechost.com]
> Sent: Wednesday, September 12, 2007 4:49 PM
> To: mysql@lists.mysql.com
> Subject: 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?
>
>
> Ta,
>
> R.
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=j...e-infoshop.com
>
>




  Réponse avec citation
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
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 04h40.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10034 seconds with 12 queries