Another great example on a simple type being faster than a object attribute:
PowerTip of the Day > Speed Up Loops.
Another facet of KISS.
2011-06-29
2011-06-27
Timestamp difference
I was looking into Windows Application Log and SQL Server Error Log to investigate a incident, and needed to calculate the effective duration of the incident.
This is actually quite simple using PowerShell and the CmdLet Get-Date:
(Get-Date "24-06-2011 08:00:24") - (Get-Date "23-06-2011 16:24:49")
Days : 0
Hours : 15
Minutes : 35
Seconds : 35
Milliseconds : 0
Ticks : 561350000000
TotalDays : 0,649710648148148
TotalHours : 15,5930555555556
TotalMinutes : 935,583333333333
TotalSeconds : 56135
TotalMilliseconds : 56135000
A more compact answer can be acquired by
((Get-Date "24-06-2011 08:00:24") - (Get-Date "23-06-2011 16:24:49")).ToString()
15:35:35
The statement converts the timestamp strings to DateTime (System.DateTime) objects, subtracts the two objects and returns a TimeSpan (System.TimeSpan) object.
This is actually quite simple using PowerShell and the CmdLet Get-Date:
(Get-Date "24-06-2011 08:00:24") - (Get-Date "23-06-2011 16:24:49")
Days : 0
Hours : 15
Minutes : 35
Seconds : 35
Milliseconds : 0
Ticks : 561350000000
TotalDays : 0,649710648148148
TotalHours : 15,5930555555556
TotalMinutes : 935,583333333333
TotalSeconds : 56135
TotalMilliseconds : 56135000
A more compact answer can be acquired by
((Get-Date "24-06-2011 08:00:24") - (Get-Date "23-06-2011 16:24:49")).ToString()
15:35:35
The statement converts the timestamp strings to DateTime (System.DateTime) objects, subtracts the two objects and returns a TimeSpan (System.TimeSpan) object.
Subscribe to:
Posts (Atom)