是否有SSRS表达式可以计算两天之间的差异(周末,周六和周日除外)?

时间:2019-03-27 18:59:18

标签: c# date reporting-services expression weekend

我能够计算两个日期之间的日期差,但是,它包括所有周末。但除了周六和周日这样的周末外,我需要有所不同。我正在使用以下表达式:

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

1 个答案:

答案 0 :(得分:1)

要在SSRS中执行此操作,请转到报告代码窗口并添加以下内容

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

在需要显示值的文本框中,添加以下表达式

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

希望这对您有所帮助。