I have a client who wants the report execution time to be displayed based on their report. To place them, I created a variable in the report (in the report properties) called "GroupExecutionTime", with the following expression:
=System.DateTime.Now
Then in the report footer there is the following:
="Execution Time: " + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0 seconds", ( IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours & " hour(s), ", "") + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds & " second(s)", "")) )
Unfortunately, the client returned, saying that they want me to show the milliseconds that were executed in the report when it takes less than one second. This is a low priority requirement, but curiosity and desire to satisfy this demand left me at a loss, how is this done? Unfortunately, System.DateTime.Now
does not store anything below seconds.
Fixed from the following (thanks Anthony Sottile answer)
="Execution Time: " + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0." & Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Milliseconds & " seconds.", ( IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours & " hour(s), ", "") + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") + IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds & " second(s)", "")) )