Jump to content

Sort By Date


abrahamgarcia27

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.