web_master Posted April 4, 2009 Share Posted April 4, 2009 Hi, <?php $QueryReturn = mysql_query('SELECT `ra_progbyday_year`, `ra_progbyday_month`, `ra_progbyday_day` FROM `ra_progbyday` ORDER BY ??? ASC '); ?> I got this query. `ra_progbyday_year`, `ra_progbyday_month` and `ra_progbyday_day` is an INT which is after reload for example: `ra_progbyday_year` = 2009, `ra_progbyday_month` = 04 and `ra_progbyday_day` = 04. I got problem after ORDER BY, because I want to "ORDER" by date after reload. How can I list this 3 params like "date"? - Or its enough to create column: `ra_progbyday_date` looks like: 20090404 Always will have a earlier date smaller nr that later date? thnanx T Quote Link to comment https://forums.phpfreaks.com/topic/152560-order-by-date/ Share on other sites More sharing options...
charleshill Posted April 4, 2009 Share Posted April 4, 2009 You can use a timestamp column to order things by their date. You can also order them using their month and year columns... ORDER BY year DESC, month DESC Haven't ever done it, but I'd imagine you can use any number of columns to order the data with... So try ORDER BY year DESC, month DESC, day DESC too if you want. Quote Link to comment https://forums.phpfreaks.com/topic/152560-order-by-date/#findComment-801272 Share on other sites More sharing options...
revraz Posted April 4, 2009 Share Posted April 4, 2009 If you would store the date correctly, you wouldn't have this problem. Quote Link to comment https://forums.phpfreaks.com/topic/152560-order-by-date/#findComment-801279 Share on other sites More sharing options...
web_master Posted April 4, 2009 Author Share Posted April 4, 2009 If you would store the date correctly, you wouldn't have this problem. Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/152560-order-by-date/#findComment-801316 Share on other sites More sharing options...
fenway Posted April 4, 2009 Share Posted April 4, 2009 - Or its enough to create column: `ra_progbyday_date` looks like: 20090404 Like revraz said, make a proper date column. In the meanwhile, an "ORDER BY CONCAT_WS( '-', ra_progbyday_year, ra_progbyday_month, ra_progbyday_day) DESC" will work. Quote Link to comment https://forums.phpfreaks.com/topic/152560-order-by-date/#findComment-801336 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.