How to fetch milliseconds using date time?
reporting-services, ssrs-2008
Solution
The resulting `TimeSpan` object from the `.Subtract()` method should 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 wouldn't record ms? If it doesn't, then this won't be of much assistance. I unfortunately can't seem to spin up my instance of SSRS to test this myself...
Problem
I have a client who wants the execution time of a report to be shown on the base of their report. To accommodate them I've created a variable on the report (under report properties) called 'GroupExecutionTime' with the following expression: ``` =System.DateTime.Now ``` Then in the footer of the report I have 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 has come back saying that they want me to show the milliseconds that the report has executed in when it's less then one second. It's a low priority requirement but curiosity and wish to satisfy the requirement have left me wondering how this is done? Unfortunately `System.DateTime.Now` doesn't appear to store anything below seconds. Fixed with the following (thanks to Anthony Sottile's 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)", "")) ) ```