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 to a DateTime. As with casting with parameters, a great deal of care is required for date formats other than US.
For example, in the UK I might write the following, yet the comparison will fail. The value on the left will convert to 13th January, 2017, but the value on the right will convert to 1st December, 2017:
(Get-Date "13/01/2017") -gt "12/01/2017"
The corrected comparison is:
(Get-Date "13/01/2017") -gt "01/12/2017"