Question:
1 2 3 |
$olddate = Get-Date -Date "31-dec-2013 00:00:00" -Format d.M.yyyy $Now = Get-date -Format d.M.yyyy |
How can I check if $olddate is earlier than $Now?
Answer:
If your store them as DateTime
instead of as formatted strings, you can use the less-than operator (-lt
) just like with regular numbers, and then use the format operator (-f
) when you need to actually display the date:
1 2 3 4 5 6 7 8 |
$olddate = Get-Date -Date "31-dec-2013 00:00:00" $Now = Get-Date if($olddate -lt $Now){ "`$olddate is in the past!" "{0:d.M.yyyy}" -f $olddate "{0:d.M.yyyy}" -f $Now } |