Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Find Time Ranges records

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-05-25 : 15:40:38
I have a DateTime field, I need to find out how many records are in 8am-11am, 12pm-5pm, 6pm-7am regardless of date. How can I do this?

Kamran Shahid
Sr. Software Engineer(MCSD.Net)
www.netprosys.com

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-25 : 18:02:32
You can get hour with datepart function like datepart(hh, getdate()).
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-25 : 23:50:21
Get the hour part of date by menas of datepart function as suggested by rmiao and group the data based on that to get the count of records in each category.
Go to Top of Page
   

- Advertisement -