Jump to content

sorting by day


doddsey_65

Recommended Posts

i need to sort my database results by the day they were added to the database. There is a column with the timestamp of when they were inserted but how do i group them by the day they were inserted so i can display them as such:

 

Mon 14th: 5 records

Tues 15th: 11 records

 

etc.

 

Link to comment
https://forums.phpfreaks.com/topic/235648-sorting-by-day/
Share on other sites

You will need to use the mysql FROM_UNIXTIME() function in your query to get the values into a yyyy-mm-dd value. From there, you can GROUP BY the part(s) of the date you want and use COUNT() to get a count of the number of records in each group.

 

Unix timestamps are the worst way to store date/time information that you need to manipulate based on calendar divisions. 

 

Link to comment
https://forums.phpfreaks.com/topic/235648-sorting-by-day/#findComment-1211175
Share on other sites

am i on the right lines with this:

 

$query = $link->query("SELECT *
                    FROM ".TBL_PREFIX."posts
                    GROUP BY FROM_UNIXTIME(p_time_posted)
                        ");
$row = $query->fetchAll();

 

Link to comment
https://forums.phpfreaks.com/topic/235648-sorting-by-day/#findComment-1211183
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.