Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: open

Message Too Old, No Replies

Grouping query by day using a timestamp

Right now it groups it by second.

     
10:23 pm on May 26, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2007
posts:97
votes: 0


Hello, I'm trying to gather some information from my database but I need to group it by the day.

I have a timestamp in my database called "created" in the format of yyyy-mm-dd hh:mm:ss.

Right now if I group by created, its grouping my users all the way down to the second. Is it possible to make my grouping by day?

Also, how might I make sure that my user counts are sorted by the creation date, where the most recent day is listed first?

Thanks.

$query=mysql_query("SELECT COUNT(users) FROM database GROUP BY created");

11:19 am on May 27, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


this may work for you:
$query=mysql_query("SELECT COUNT(users), TO_DAYS(created) AS day FROM database GROUP BY day DESC");
7:07 pm on May 27, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2007
posts:97
votes: 0


Thats awesome!

Thank you for your help. It works perfectly and is a very useful tool I can add to my toolbox.

Thanks.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members