alexsmith2709 Posted March 27, 2011 Share Posted March 27, 2011 Hi, I've done a search and cant find anything related to my problem. I have a newsfeed on my site and i want it to display with the latest news at the top. I have this code: $get_news = "SELECT title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; This works fine on one of my sites but on another i've just hit a problem. It seems to sort only by the day, not the rest of the date. I made a news post today with date and time of "27 Mar 2011 at 12:54:02" but a post from "28 Jan 2011 at 19:59:52" is above it. Any ideas why this is happening? Thanks, Alex Quote Link to comment https://forums.phpfreaks.com/topic/231844-strange-sort-by-date-and-time-problem/ Share on other sites More sharing options...
silkfire Posted March 27, 2011 Share Posted March 27, 2011 How is your time shown in the database? What format? Quote Link to comment https://forums.phpfreaks.com/topic/231844-strange-sort-by-date-and-time-problem/#findComment-1192831 Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2011 Share Posted March 27, 2011 User a different alias name in - AS datetime When you use an alias name that is the same as a column name, the alias data value is used where you reference that name in the query instead of the actual column. Your query is ORDERing BY the formatted datetime instead of the actual datetime. DATE and DATETIME data types can be ordered correctly. Your formated datetime cannot. Quote Link to comment https://forums.phpfreaks.com/topic/231844-strange-sort-by-date-and-time-problem/#findComment-1192897 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.