abrahamgarcia27 Posted April 10, 2013 Share Posted April 10, 2013 I am trying to sort by date my date posted format is the following 4/9/2013 -> Month / Day / Year I am using the following query (I want to put the newest at top) $mainQuery = "SELECT SQL_CALC_FOUND_ROWS * FROM `".TABLE_BLOG."` ORDER BY DATE(posted_date) DESC LIMIT ".(int)($perPage*($p-1)).','.(int)$perPage." "; But it is not ordering correctly the information Could anyone help me figure this out? Link to comment https://forums.phpfreaks.com/topic/276794-sort-by-date/ Share on other sites More sharing options...
Barand Posted April 10, 2013 Share Posted April 10, 2013 to sort dates they need to be in a sortable format, which is YYYY-MM-DD Either change your date fields to type DATE and use that format (recommended) or convert the date in the/every query to that format using STR_TO_DATE() function. Link to comment https://forums.phpfreaks.com/topic/276794-sort-by-date/#findComment-1424022 Share on other sites More sharing options...
abrahamgarcia27 Posted April 11, 2013 Author Share Posted April 11, 2013 to sort dates they need to be in a sortable format, which is YYYY-MM-DD Either change your date fields to type DATE and use that format (recommended) or convert the date in the/every query to that format using STR_TO_DATE() function. Thanks i just changed the date field to DATE. Link to comment https://forums.phpfreaks.com/topic/276794-sort-by-date/#findComment-1424050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.