powershell - Two identical datetimes not comparing equal -
i have 2 dates identical far can tell.
$thedate = (get-date -hour 0 -minute 00 -second 00) $otherdate = (get-date -hour 0 -minute 00 -second 00)
executed in order
both of these show monday, may 11, 2015 12:00:00 am
, when ($thedate -eq $otherdate)
returns false. i've tried $thedate.equals($otherdate)
, (($thedate) -eq ($otherdate))
same thing. thing can return true ($thedate -gt $otherdate)
crazy or noob?
you forgetting millisecond field, different 2 datetimes:
ps > $thedate = (get-date -hour 0 -minute 00 -second 00) ps > $otherdate = (get-date -hour 0 -minute 00 -second 00) ps > $thedate.millisecond 122 ps > $otherdate.millisecond 280
setting these fields same value fixes problem:
ps > $thedate = (get-date -hour 0 -minute 00 -second 00 -millisecond 000) ps > $otherdate = (get-date -hour 0 -minute 00 -second 00 -millisecond 000) ps > $thedate -eq $otherdate true
although might easier assign 2 variables same datetime:
ps > $thedate = (get-date -hour 0 -minute 00 -second 00) ps > $otherdate = $thedate ps > $thedate -eq $otherdate true
Comments
Post a Comment