Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between dates using PowerShell

Tags:

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?