-
# of weekdays between dates Excluding Sat/Sun
Does anyone know how to write code to tell the amount of days between 2 dates excluding Saturday and Sunday.
Datediff will tell me the total amount of days and I guess I need some logic to look at the startdate and manipulate the total after the fact.
Any thoughts or solutions out there?
-
# of weekdays between dates Excluding Sat/Sun (reply)
Hi,
here is pseudo code how to:
firstdate date
lastdate date
udate date
totaldays int
intSS int
udate = stardate
totaldays = use datediff
for 1 to totaldays
if DatePart("w", udate) = 1 Or DatePart("w", udate) = 7 Then
intSS = intSS + 1
End If
udate = DateAdd("d", 1, udate)
Next
WorkingDays = totaldays - intSS
------------
Trevor at 5/14/2002 7:24:03 AM
Does anyone know how to write code to tell the amount of days between 2 dates excluding Saturday and Sunday.
Datediff will tell me the total amount of days and I guess I need some logic to look at the startdate and manipulate the total after the fact.
Any thoughts or solutions out there?
-
# of weekdays between dates Excluding Sat/Sun (reply)
Hi,
here is pseudo code how to:
firstdate date
lastdate date
udate date
totaldays int
intSS int
udate = stardate
totaldays = use datediff
for 1 to totaldays
if DatePart("w", udate) = 1 Or DatePart("w", udate) = 7 Then
intSS = intSS + 1
End If
udate = DateAdd("d", 1, udate)
Next
WorkingDays = totaldays - intSS
------------
Trevor at 5/14/2002 7:24:03 AM
Does anyone know how to write code to tell the amount of days between 2 dates excluding Saturday and Sunday.
Datediff will tell me the total amount of days and I guess I need some logic to look at the startdate and manipulate the total after the fact.
Any thoughts or solutions out there?
-
# of weekdays between dates Excluding Sat/Sun (reply)
Thanks jkv......tcd
------------
jkv at 5/14/2002 8:28:50 AM
Hi,
here is pseudo code how to:
firstdate date
lastdate date
udate date
totaldays int
intSS int
udate = stardate
totaldays = use datediff
for 1 to totaldays
if DatePart("w", udate) = 1 Or DatePart("w", udate) = 7 Then
intSS = intSS + 1
End If
udate = DateAdd("d", 1, udate)
Next
WorkingDays = totaldays - intSS
------------
Trevor at 5/14/2002 7:24:03 AM
Does anyone know how to write code to tell the amount of days between 2 dates excluding Saturday and Sunday.
Datediff will tell me the total amount of days and I guess I need some logic to look at the startdate and manipulate the total after the fact.
Any thoughts or solutions out there?
-
# of weekdays between dates Excluding Sat/Sun (reply)
Hi Guys,
Here is a single select statement solution.
Just take @stDate as Start Date and @endDate as End Date...
Declare @stDate datetime
Declare @endDate datetime
select @stDate = '05/04/2002'
select @endDate = '05/26/2002'
Select
( Case When datepart(dw,@stDate) = 1 And datepart(dw,@endDate) = Then
(datediff(dd,@stDate,@enddate) - datediff(wk,@stDate,@enddate) * 2 ) - 1
When datepart(dw,@stDate) = 1 or datepart(dw,@endDate) = 7 Then
(datediff(dd,@stDate,@enddate) - datediff(wk,@stDate,@enddate) * 2 )
else
(datediff(dd,@stDate,@enddate) - datediff(wk,@stDate,@enddate) * 2 ) + 1
end
) As 'NoOfDays'
will give you the exact no.of. working days.... excluding saturdays and sundays....
Prasad
------------
Trevor at 5/14/2002 8:39:02 AM
Thanks jkv......tcd
------------
jkv at 5/14/2002 8:28:50 AM
Hi,
here is pseudo code how to:
firstdate date
lastdate date
udate date
totaldays int
intSS int
udate = stardate
totaldays = use datediff
for 1 to totaldays
if DatePart("w", udate) = 1 Or DatePart("w", udate) = 7 Then
intSS = intSS + 1
End If
udate = DateAdd("d", 1, udate)
Next
WorkingDays = totaldays - intSS
------------
Trevor at 5/14/2002 7:24:03 AM
Does anyone know how to write code to tell the amount of days between 2 dates excluding Saturday and Sunday.
Datediff will tell me the total amount of days and I guess I need some logic to look at the startdate and manipulate the total after the fact.
Any thoughts or solutions out there?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|