Sunday, February 12, 2012

Business Days between 2 Dates

I'm new to Reporting services and I would like to be able to dispay a
calculated field showing the number of business days, or business hours
betweeen 2 dates. Anyone have some thoughts? Or better yet, a code
snippet?Paste this in the Code window in report properties dialog and Refer to it in
the report items as: =Code.NumberOfWeekDays( Parameters!InitialDate.Value ,
Parameters!FinalDate.Value )
public shared Function NumberOfWeekDays(InitialDate As DateTime, FinalDate
As DateTime) As Integer
Dim totalDays As Integer
Dim workingDays As Integer
Dim dateTemp As Date
Dim i As Integer
totalDays = DateDiff(DateInterval.Day, InitialDate, FinalDate)
workingDays = 0
dateTemp = InitialDate
For i = 0 To totalDays
dateTemp = DateAdd(DateInterval.Day, i, InitialDate)
Select DateAdd(DateInterval.Day, i, InitialDate).DayOfWeek
Case DayOfWeek.Saturday:
Case DayOfWeek.Sunday:
workingDays += 0
Case Else:
workingDays += 1
End Select
Next i
return workingDays
End Function
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Dave Bodenheimer" <dave@.edgeinformation.com> wrote in message
news:%23g3EQ8RgEHA.2916@.TK2MSFTNGP12.phx.gbl...
> I'm new to Reporting services and I would like to be able to dispay a
> calculated field showing the number of business days, or business hours
> betweeen 2 dates. Anyone have some thoughts? Or better yet, a code
> snippet?
>

No comments:

Post a Comment