Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff or Between 2 Dates Need to Exclude Sundays 2

Status
Not open for further replies.

cghoga

Programmer
Jun 26, 2003
614
US
Greetings,

I have a situation where I need to check if a call occurs between 2 dates. This is easy, the problem I am having is it needs to consider business days only which in my situation would exclude Sundays.

So if it was Monday morning and a call had occurred Saturday morning at the same time, it would not be considered 2 biz days until Tuesday morning that same time.

I am using SQL 2000.

Thanks for any and all help,

cgh
 
Hi,

Would this work for you?

Code:
declare @temp table (id int, adate datetime)
insert into @temp values (1, '2009-06-01')
insert into @temp values (1, '2009-06-02')
insert into @temp values (1, '2009-06-06') -- sat
insert into @temp values (1, '2009-06-07') -- sun
insert into @temp values (1, '2009-06-08') 
insert into @temp values (1, '2009-06-09') 
insert into @temp values (2, '2009-06-01') 
insert into @temp values (2, '2009-06-02') 
insert into @temp values (2, '2009-06-07') -- sat

select id, 
sum(case when DATENAME(dw,adate) in ('Saturday','Sunday') then 0 else 1 end) as count
from @temp
group by id

Ryan
 
Can you post your current query and where exactly do you need help?
 
Thanks guys,

Here is the basic code snipped prior to exclusion...

IF DATEDIFF ( d, calldatetime , getdate()) <= 2 Biz Days then delete from temp table

If a Sunday falls between the startdate and enddate I need to not count the Sunday.

Thanks again,

cgh
 
What about holidays other days off?

What id whould do is have a dates table

1/1/2000
1/2/2000
1/3/2000
.....
12/29/2xxx
12/30/2xxx
12/31/2xxx
for statrers
Code:
Select count(*),calldatetime 
from CallTable
inner join(
           Select Dayofyear
            from Daystable
            Where datepart(dw,Dayofyear) Between 2 and 6
            and holiday=0
            )Daystable
on CallTable.calldatetime Between Dayofyear and getdate()
Group by calldatetime
 
Thanks for all the help, will take a look see.

Thanks,

cgh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top