webguy262 Posted March 6, 2008 Share Posted March 6, 2008 Trying to find events prior to today's date, and order them chronologically, either asc or dsc. Here's what I've got, but they display out of order. What am I missing? $today = date("Ymd"); $query = "SELECT title, link, chapter, DATE_FORMAT(start_date, '%M %d, %Y') AS start_date, DATE_FORMAT(start_date, 'Ymd') AS chrono, city, state FROM events_calendar WHERE start_date < $today order by chrono"; Link to comment https://forums.phpfreaks.com/topic/94708-help-ordering-by-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2008 Share Posted March 6, 2008 The format string in the following is not valid - DATE_FORMAT(start_date, 'Ymd') AS chrono, but that whole term is unnecessary. Also, I am not sure what the results of using an alias of start_date when there is a column by that name would be. What is the format of your start_date column - DATE or DATETIME? Once I know what start_date is, I can show you a very simple query to do what you want. Link to comment https://forums.phpfreaks.com/topic/94708-help-ordering-by-date/#findComment-484891 Share on other sites More sharing options...
webguy262 Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks for helping! start_date is DATE Link to comment https://forums.phpfreaks.com/topic/94708-help-ordering-by-date/#findComment-485350 Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2008 Share Posted March 6, 2008 This should give the same results - $query = "SELECT title, link, chapter, DATE_FORMAT(start_date, '%M %d, %Y') AS date, city, state FROM events_calendar WHERE start_date < CURDATE() order by start_date"; Your can use ORDER BY with a DATE type directly and CURDATE() (and CURRENT_DATE, CURRENT_DATE()) give you the date directly (no need for any slow php code.) Link to comment https://forums.phpfreaks.com/topic/94708-help-ordering-by-date/#findComment-485360 Share on other sites More sharing options...
webguy262 Posted March 7, 2008 Author Share Posted March 7, 2008 Works perfectly! Thanks! Link to comment https://forums.phpfreaks.com/topic/94708-help-ordering-by-date/#findComment-486005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.