Jump to content

Date problem , ORDER BY


JohneeMac

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.

Link to comment
https://forums.phpfreaks.com/topic/3178-date-problem-order-by/
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.

Link to comment
https://forums.phpfreaks.com/topic/3178-date-problem-order-by/#findComment-10816
Share on other sites

Archived

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

×
×
  • Create New...

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.