title: How to Compare two dates in PowerShell & get difference in minutes
body: <p>I need to compare LastWriteTime of a file and compare it to the current time. if the difference is greater then 45 minutes then I need to get a email alert.</p>
  
  <p>Here is what I got so far.</p>
  
  <pre><code>$StartDate=(GET-DATE)
  
  $EndDate=[datetime]”01/01/2014 00:00”
  
  NEW-TIMESPAN –Start $StartDate –End $EndDate
  </code></pre>
  
  <p>In code above I need to replace <code>$EndDate</code> with <code>Get-Item C:\Users\myusername\Desktop\file.html | select LastWriteTime</code></p>
  
  <p>I need to compare the LastWriteTime of file.html with current time.</p>
  
  <p>Please help me store 
  <code>Get-Item C:\Users\myusername\Desktop\file.html | select LastWriteTime</code> into <code>$EndDate</code> </p>
  
  <p>so I can do the compare.</p>