Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does powershell insist 18 is less than 9?

Tags:

powershell

Screenshot

Why does this come up true? (The Get-Date is set to 18 Right now...) Is it maybe something with the way Get-Date formats the number? I'm stumped....

like image 678
Johnny Heisler Avatar asked Dec 13 '22 23:12

Johnny Heisler


1 Answers

As a few have said already, you're doing a string comparison rather than a number comparison

$Time = Get-Date -Format %H
$Time.GetType()

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

In order to do what you want, you can cast your $Time to a number

[int]$Time -lt 9 
#or with a little trick 
+$Time -lt 9
like image 97
SomeShinyObject Avatar answered Dec 29 '22 11:12

SomeShinyObject