How to count number of records present in a date range between a fixed time in SQL Server? -


i need number of records present in [recordstable] last 3 months. catch need records processed between 10pm , 2am.

for example --

07/01/2015 10pm -- 07/02/2015 2am  07/02/2015 10pm -- 07/03/2015 2am 07/03/2015 10pm -- 07/04/2015 2am 

the below sql gives me records present on particular day starting may,2015.

but not able timing(10pm-2am of next day) embedded in sql , need help.

select convert(varchar(12), recorddate, 101),count(recordid) [recordstable](nolock) recorddate > '2015-05-01' group convert(varchar(12), recorddate, 101) 

mssql supports both date , time datatypes. can break statement reflect both date , time conditions separately.

select count(records) table convert(date,datecol) between 'mm/dd/yyyy' , 'mm/dd/yyyy' , convert(time,datecol) between 'hh:mm:ss' , 'hh:mm:ss' 

Comments