Jump to content

Archived

This topic is now archived and is closed to further replies.

JohneeMac

Date problem , ORDER BY

Recommended Posts

Hi there, i am trying to display some news with the most recent date at the top

 

heres my SQL:

 

$sql = mysql_query("SELECT *,
   date_format(article_date, '%D %M, %Y') as article_date 
   FROM news_system
   ORDER BY article_date 
   ASC LIMIT 5");

 

It seems to mess up and have a random order of things.

 

Thx.

Share this post


Link to post
Share on other sites

[!--quoteo(post=335531:date=Jan 11 2006, 10:35 AM:name=JohneeMac)--][div class=\'quotetop\']QUOTE(JohneeMac @ Jan 11 2006, 10:35 AM) 335531[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Hi there, i am trying to display some news with the most recent date at the top

 

heres my SQL:

 

$sql = mysql_query("SELECT *,
   date_format(article_date, '%D %M, %Y') as article_date 
   FROM news_system
   ORDER BY article_date 
   ASC LIMIT 5");

 

It seems to mess up and have a random order of things.

 

Thx.

 

It most certainly will. The mysql engine sees the dates like this (12.10.2005 -> 12102005, 24.12.1856 -> 24121856) so 24121856 is definetly bigger then 12102005.

 

The date format should be arranged first by year, then by month and then date. Or maybe use TIMESTAMP() instead.

Share this post


Link to post
Share on other sites

See the reponse to [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=82577\" target=\"_blank\"]this thread[/a] for the answer.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.