I wanted to post this solution to a Powershell problem I had because I couldn't find any examples on the internet.
I needed to be able to calculate the difference between a timestamp from the last 24 hours, and the current time.
The input and output formats needed to be hh:mm:ss
Here's how I did it:
Powershell
1 2 3 4 5 6 7 8 9 10 11 12 13 | $Time1="15:30:00"$Time2=Get-Date-formatHH:mm:ss$TimeDiff=New-TimeSpan$Time1$Time2if($TimeDiff.Seconds-lt0){$Hrs=($TimeDiff.Hours)+23$Mins=($TimeDiff.Minutes)+59$Secs=($TimeDiff.Seconds)+59}else{$Hrs=$TimeDiff.Hours$Mins=$TimeDiff.Minutes$Secs=$TimeDiff.Seconds}$Difference='{0:00}:{1:00}:{2:00}'-f$Hrs,$Mins,$Secs$Difference |
I hope this helps someone else.
Russ