February 2019
Intermediate to advanced
626 pages
15h 51m
English
DateTime objects may be compared using PowerShell's comparison operators:
$date1 = (Get-Date).AddDays(-20) $date2 = (Get-Date).AddDays(1) $date2 -gt $date1
Dates can be compared to a string; the value on the right-hand side will be converted into DateTime. As with casting with parameters, a great deal of care is required for date formats other than those used in the US.
For example, in the UK, I might write the following code, yet the conversion will fail. The value on the left will convert into 13th January, 2017, but the value on the right will convert into 1st December, 2017:
(Get-Date "13/01/2017") -gt "12/01/2017"
The corrected conversion is as follows:
(Get-Date "13/01/2017") -gt "01/12/2017"
Read now
Unlock full access