I am learning Windows PowerShell, and I am trying to get the months difference given two dates:
For example: end: 2014-06-01
now: 2014-01-10
answer: 6 months
$now = get-date
$date = $end -as [DateTime];
if (!$date)
{
'You entered an invalid date'
}
else
{
$nts = ($now - $end).Months
write-output $nts
}
I have tried everything, and I can't get the correct months in PowerShell. How can I fix it?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With