OAFC_Rob Posted September 6, 2011 Share Posted September 6, 2011 I have a news article table with a field set to "DATETIME", when I'm running the SQL i'm formatting the using SQL rather than PHP and then ordering by the date / time. However, I noticed yesterday that it was only sorting via the date and not the date and then the time. Should I swap it to a date and timestamp, as in two seperate fields. SELECT tbl_news_id, headline, article, DATE_FORMAT(datePublished, '%D %M %Y @ %H:%i' ) AS datePublished, rssFeed FROM tbl_news ORDER BY datePublished ASC LIMIT 2 Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 6, 2011 Share Posted September 6, 2011 I'm pretty confident that whatever you do during the select has no bearing on the field used in the group by.... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2011 Share Posted September 6, 2011 Use a DIFFERENT alias name for the DATE_FORMAT output so that mysql can order by your original column, not the DATE_FORMAT output. Quote Link to comment Share on other sites More sharing options...
OAFC_Rob Posted September 6, 2011 Author Share Posted September 6, 2011 What and then order by DESC, which would put in the following order correct UK Date Format 05.09.2011 @ 16.47 05.09.2011 @ 16.45 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2011 Share Posted September 6, 2011 DATE_FORMAT(datePublished, '%D %M %Y @ %H:%i' ) AS use_a_different_name_here, ORDER BY datePublished <---- so that the ORDER BY will use your datePublished column values instead of the DATE_FORMAT() output. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.