Mohsin A.
Mohsin A.

Reputation: 163

Is there an SSRS expression for calculating difference between two days excluding weekends, Saturday and Sunday?

I'm able to calculate date difference between two dates, however, its include all weekends. But I need difference excluding weekends like Saturday and Sunday. I am using below expression:

=DateDiff("d", Fields!StartDate.Value,Fields!EndDate.Value)

Upvotes: 0

Views: 472

Answers (1)

Deepak
Deepak

Reputation: 81

To do this in SSRS, go to the report code window and add the below

Function getWorkingDaysCount(ByVal tFrom As Date, ByVal tTo As Date) As Integer

    Dim tCount As Integer
    Dim tProcessDate As Date = tFrom
    For x as Integer= 1 To DateDiff(DateInterval.Day, tFrom, tTo) + 1
      If Not (tProcessDate.DayOfWeek = DayOfWeek.Saturday Or tProcessDate.DayOfWeek = DayOfWeek.Sunday) Then
        tCount = tCount + 1
      End If
      tProcessDate = DateAdd(DateInterval.Day, 1, tProcessDate)
    Next
    Return tCount

End Function

In the textbox where you need to display the value, add the below expression

=Code.getWorkingDaysCount(parameters!StartDate.Value,parameters!EndDate.Value)

Hope this helps you.

Upvotes: 1

Related Questions