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. Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/ 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. Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/#findComment-510319 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. Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/#findComment-510344 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 Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/#findComment-510545 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()); Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/#findComment-510932 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. Link to comment https://forums.phpfreaks.com/topic/99779-date-order-question/#findComment-510980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.