Monday, June 7, 2021

Report Elapsed Time for SSRS report

  1. Add a new report variable named thisTime with value of =DateTime.Now
  2. Add the following code snippet to the Report Code section:

    Public Dim execText As String

    ' for this function to work,
    ' the following Report Variable needs to be defined and set.
    ' thisTime =DateTime.Now

    Public Function LapseTime(execTime as Date, sysTime as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable) As String

        Dim ElapsedMins As Integer 
        Dim ElapsedSecs As Integer 

        Dim currTime As System.DateTime = sysTime.Value

        If (ExecText = "") Then
            'Calculate execution time here
            ElapsedMins = DateDiff(DateInterval.Minute, execTime , currTime) mod 60 
            ElapsedSecs = DateDiff(DateInterval.Second, execTime , currTime) mod 60

            execText = ElapsedMins.ToString() & "m " & ElapsedSecs.ToString() & "s"
            'execText = ElapsedMins.ToString() & ":" & Right("0" & ElapsedSecs.ToString(), 2)
        End If

        Return execText

    End Function

  3. To use it, create a new textbox and enter the following in the Expression:

    =Code.LapseTime(Globals!ExecutionTime,Variables!thisTime)

  4. Done!

No comments:

Post a Comment