title: Calculate Duration Between Two Dates with Javascript
body: <p>I basically want to have two dates, i.e:</p>
  
  <pre><code> var startDate = new Date("01/01/2001 01:00:00");
   var currentDate = new Date();
  </code></pre>
  
  <p>Then I want to get the duration by subtracting <code>startDate</code> from <code>currentDate</code> and display it in the form of: <strong>a years b month(s) c day(s) d hour(s) e second(s)</strong>.</p>
  
  <p>My problem so far has been that if you take the shortcut, i.e:</p>
  
  <pre><code>var duration = currentDate.getTime() - startDate.getTime();
  var seconds = duration / 1000;
  var minutes = duration / 1000 / 60;
  </code></pre>
  
  <p>etc...</p>
  
  <p>Then you get a false duration because, for example, months aren't always 30 days, years aren't always 365 days (leap years), etc. Not to mention that somehow when I did this it was off by roughly a year.</p>
  
  <p>I've looked around the web and through various posts on StackOverflow but I couldn't find a working example of a JavaScript method that accurately subtracts one date from another and allows you to get the details (year, month, day, hour, minute, second) from the result date.</p>
  
  <p>There is a website that can already do this exactly how I'd like to do it: <a href="http://www.timeanddate.com/date/timeduration.html?d1=&amp;m1=&amp;y1=&amp;d2=&amp;m2=&amp;y2=" rel="nofollow">http://www.timeanddate.com</a></p>