Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATE_FORMAT() ORDER BY

Status
Not open for further replies.

squidster

Technical User
Oct 13, 2002
55
GB
Hi,

I have been having problems with UK and MySQL date formats and have been able to resolve most of them so that dates inserted and queried are all ok. However, I have just noticed something strange when attempting to select dates using ORDER BY date ASC/DESC:-

SELECT Id, Id2, Title, Type, Desc, DATE_FORMAT(Date, '%d/%m/%Y') AS Date FROM table WHERE Date >= CURRENT_DATE() ORDER BY Date ASC

This produces a list with dates in UK format but they are not sorted in correct order. It seems to sort left to right by day/month/year.

If I take out the DATE_FORMAT() and leave ORDER BY date ASC then it works fine with the MySQL date format as it sorts in same order but year/month/day.

Does anyone know how/if this can be done with the select, or will I have to reformat the date in the app?

thanks
 
You are ordering by the formatted date value.

Code:
SELECT Id, Id2, Title, Type, Desc, DATE_FORMAT(Date, '%d/%m/%Y') AS fDate FROM table WHERE Date >= CURRENT_DATE() ORDER BY Date ASC
 
I can be incredibly dumb sometimes it scares me!!

[blush]

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top