Two identical datetimes not comparing equal


I have two dates that are identical as far as I can tell.

Executed in that order

Both of these show up as Monday, May 11, 2015 12:00:00 AM, but when I do ($theDate -eq $otherDate) it returns false. I’ve tried $theDate.equals($otherDate) and (($theDate) -eq ($otherDate)) same thing.
The only thing I can get to return true is ($theDate -gt $otherDate)
Am I crazy or just a noob?


You are forgetting about the millisecond field, which will be different for the two datetimes:

Setting these fields to the same value fixes the problem:

Although it might be easier to just assign the two variables to the same datetime:


Two identical datetimes not comparing equal by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply