1

I'm writing a script that will compare times between 2 servers, and compare the time difference. The returned timestamp is in the format below:

-00:00:01.9989999
-01:00:02 
-00:00:00.9989999

I need to create a condition where the action would be triggered, only if the difference is greater then 3 minutes. How should I format this?

3
  • Unless you can guarantee both of the time stamps being compared are on the same day, you're going to need a date component to go along with the time stamps to get accurate results. Commented Jun 3, 2015 at 15:19
  • 2
    ([timespan]'-00:00:00.9989999').Duration() -gt (New-TimeSpan -Minutes 3) Commented Jun 3, 2015 at 15:29
  • @mjolinor I'm converting the datetime objects to UTC first, and all are within the same physical boundary (US), so I would be very shocked if there was a difference in date. Commented Jun 3, 2015 at 15:51

1 Answer 1

1

As @PetSerAl suggested, cast the times to timespans, get the Duration() of their difference (the absolute value of the difference, if you will), and compare it to a timespan of 3 minutes:

$t1 = [timespan]'-00:00:01.9989999'
$t2 = [timespan]'-00:00:00.9989999'

$delta = ($t1 - $t2).Duration()

if ($delta -gt [timespan]'00:03:00') {
  # do stuff
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.