vendredi 10 mai 2019

Why is this false? datetime comparison

I'm trying to compare some datetime strings and not sure why this is false?

PS> ( (get-date -f 'G') -gt ($ZeroHundred) -and (get-date -f 'G') -lt ($OFourHundred) )
False

PS> get-date -f 'G'
5/11/2019 1:20:53 AM

PS> $ZeroHundred
5/11/2019 12:00:00 AM

PS> $OFourHundred
5/11/2019 4:00:00 AM

PS> (get-date -f 'G').GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                         
-------- -------- ----                                     --------                                                                                                                                         
True     True     String                                   System.Object                                                                                                                                    



PS> $ZeroHundred.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                         
-------- -------- ----                                     --------                                                                                                                                         
True     True     String                                   System.Object                                                                                                                                    



PS> $OFourHundred.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                         
-------- -------- ----                                     --------                                                                                                                                         
True     True     String                                   System.Object                                                                                                                                    



When I break it down a bit I see why, but I don't understand why:

PS> (get-date -f 'G') -lt ($OFourHundred)
True

PS> (get-date -f 'G') -gt ($ZeroHundred)
False

isn't 5/11/2019 1:20:53 AM greater than 5/11/2019 12:00:00 AM???

Aucun commentaire:

Enregistrer un commentaire