homepage Welcome to WebmasterWorld Guest from 54.196.197.153
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Grouping query by day using a timestamp
Right now it groups it by second.
otem




msg:3350870
 10:23 pm on May 26, 2007 (gmt 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");

 

phranque




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

this may work for you:
$query=mysql_query("SELECT COUNT(users), TO_DAYS(created) AS day FROM database GROUP BY day DESC");

otem




msg:3351236
 7:07 pm on May 27, 2007 (gmt 0)

Thats awesome!

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

Thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved