all groups > sql server new users > april 2006 >
You're in the

sql server new users

group:

how to group only by DATE, not include time


Re: how to group only by DATE, not include time Tom Moreau
4/21/2006 9:43:06 PM
sql server new users: Try:

select
cast (char (8), ColDatetime)) as ColDatetime
, count (*)
from
MyTable
group by
cast (char (8), ColDatetime))

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
[quoted text, click to view]
Hi,

SQL Server only has datetime datatype, but in most of the case, we only need
date. If data the datetime column has time, how to group only by date.
for example,
If the table has following data
ColDatetime
04/20/06 12:23:35
04/20/06 13:23:00
04/20/06 14:23:00

If run
Select Coldatetime,count(*) From Table Group by ColDatetime
The resule is:
04/20/06 12:23:35 1
04/20/06 13:23:00 1
04/20/06 14:23:00 1

But I really wanted is
04/20/06 3

Thanks

how to group only by DATE, not include time Taoge
4/22/2006 12:00:00 AM
Hi,

SQL Server only has datetime datatype, but in most of the case, we only need
date. If data the datetime column has time, how to group only by date.
for example,
If the table has following data
ColDatetime
04/20/06 12:23:35
04/20/06 13:23:00
04/20/06 14:23:00

If run
Select Coldatetime,count(*) From Table Group by ColDatetime
The resule is:
04/20/06 12:23:35 1
04/20/06 13:23:00 1
04/20/06 14:23:00 1

But I really wanted is
04/20/06 3

Thanks

AddThis Social Bookmark Button