Page 1 of 1

How to sort date from past to present

Posted: Wed Dec 02, 2009 1:11 am
by rei27
I wishes my data will show according to the date, but no matter how i try, it cannot be!

I am using this code:

Code: Select all

SELECT * FROM customer ORDER BY date DESC
The result shows as:
1 Jacky 30.11.2009
2 Willy 02.12.2009
3 Jason 01.12.2009
Actually I wishes my result show as:
1 Willy 02.12.2009
2 Jason 01.12.2009
3 Jacky 30.11.2009

Re: How to sort date from past to present

Posted: Wed Dec 02, 2009 2:18 am
by John Cartwright
You need to either change your date format, or better yet use the DATE field (which comes along with many great date functions). The reason why you are getting unexpected results if because these are being treated as strings. To mysql, it simply looks like

30112009
02122009
01122009

So yes, they are being ordered correctly against your query. You would need to format your dates by YYYY.MM.DD for this to work without the DATE field.