How to get milliseconds using a time date?

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)", "")) ) 
+4
source share
1 answer

The resulting TimeSpan from the .Subtract() method must have a .Milliseconds property that you can print.

http://msdn.microsoft.com/en-US/library/system.timespan.milliseconds%28v=vs.90%29

I'm not sure why DateTime.Now is not writing ms? If this does not happen, then it will not be very useful. Unfortunately, I can't seem to deploy my SSRS instance to test this myself ...

+5
source

Source: https://habr.com/ru/post/1415885/


All Articles