Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
group by - ignoring the time part of a timestamp?
Old 01-10-2011, 05:26 AM group by - ignoring the time part of a timestamp?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi guys,

I have a timestamp field like: 2011-01-03 18:29:44

I want to get how many rows for each date,

ie:
select count(*) from table group by time;

However this obviously returns a lot of rows ( as its counting the hours and miniutes )

How can i get it to just group by 2011-01-03 rather than 2011-01-03 18:29:44

Ie: group by yyyy-mm-dd rather than yyyy-mm-dd hh:mm:ss


Google isnt being too helpful.

Thanks
G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 01-10-2011, 03:39 PM Re: group by - ignoring the time part of a timestamp?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Well well,
With no answers ive spent the best part of all day hunting for the best way to do it.

This is what i have ( and works )

SELECT DATE_FORMAT(DATE(time ) , '%m/%d/%y' ) , COUNT( time ) AS counted
FROM visitors
GROUP
BY DATE( time )


Thought id share for others having the same issue one day.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 01-21-2011, 03:41 PM Re: group by - ignoring the time part of a timestamp?
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
select count(1), to_char(date_field, "yyyy-mm-dd") from visitors group by to_char(date_field, "yyyy-mm-dd") ;
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 01-21-2011, 04:12 PM Re: group by - ignoring the time part of a timestamp?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Thanks Paul. Better late than never lol

Always welcome other ways to do things..
I wonder which way will be more cpu intensive?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to group by - ignoring the time part of a timestamp?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17005 seconds with 12 queries