Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.