title: Difference between dates using PowerShell
body: <p>I am learning Windows PowerShell, and I am trying to get the months difference given two dates:</p>
  
  <pre><code>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
      }
  </code></pre>
  
  <p>I have tried everything, and I can't get the correct months in PowerShell. How can I fix it?</p>