cturner Posted April 6, 2008 Share Posted April 6, 2008 I am wondering if someone, could please tell me how I can display database content in date order? I have a date column that is a date type. I would like the date to be shown like this: Wednesday, March 1, 2008. I would also like the date to be ordered with the year then the month then the date of that month. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 6, 2008 Share Posted April 6, 2008 Assuming it's a proper DATE field, ordering by that field will order by year/month/day, correctly. You can use DATE_FORMAT() to extract whatever format you'd like. Quote Link to comment Share on other sites More sharing options...
cturner Posted April 6, 2008 Author Share Posted April 6, 2008 Thanks for that fenway. How do I display all of the different dates into this order: Wednesday, March 1, 2008 Thursday, March 2, 2007 and so on? With the most recent media release at the top. Quote Link to comment Share on other sites More sharing options...
mwasif Posted April 6, 2008 Share Posted April 6, 2008 You need to make such query SELECT DATE_FORMAT(date_column, '%W, %M %e, %Y') FROM table ORDER BY date_column DESC Quote Link to comment Share on other sites More sharing options...
cturner Posted April 7, 2008 Author Share Posted April 7, 2008 I have tried that mwasif. It doesn't display in the order that I want. Anyway here is a part of my code that is revelant to what we are talking about: $query5 = mysql_query("SELECT title, DATE_FORMAT(date, '%W, %M %e, %Y') as date FROM `mediareleases` ORDER BY date ASC") or die("Could not query because: ".mysql_error()); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 7, 2008 Share Posted April 7, 2008 Don't use date as the alias name in the select. That will cause the ORDER BY date to use the output of the DATE_FORMAT() function instead of your date column. 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.