title: Difference between two dates in years, months, days in JavaScript
body: <p>I've been searching for 4 hours now, and have not found a solution to get the difference between two dates in years, months, and days in JavaScript, like: 10th of April 2010 was 3 years, x month and y days ago.</p>
  
  <p>There are lots of solutions, but they only offer the difference in the format of either days OR months OR years, or they are not correct (meaning not taking care of actual number of days in a month or leap years, etc). Is it really that difficult to do that? </p>
  
  <p>I've had a look at: </p>
  
  <ul>
  <li><a href="http://momentjs.com/" rel="noreferrer">http://momentjs.com/</a> -> can only output the difference in either years, months, OR days</li>
  <li><a href="http://www.javascriptkit.com/javatutors/datedifference.shtml" rel="noreferrer">http://www.javascriptkit.com/javatutors/datedifference.shtml</a></li>
  <li><a href="http://www.javascriptkit.com/jsref/date.shtml" rel="noreferrer">http://www.javascriptkit.com/jsref/date.shtml</a></li>
  <li><a href="http://timeago.yarp.com/" rel="noreferrer">http://timeago.yarp.com/</a></li>
  <li>www.stackoverflow.com -> Search function</li>
  </ul>
  
  <p>In php it is easy, but unfortunately I can only use client-side script on that project. Any library or framework that can do it would be fine, too.</p>
  
  <p>Here are a list of expected outputs for date differences:</p>
  
  <pre><code>//Expected output should be: "1 year, 5 months".
  diffDate(new Date('2014-05-10'), new Date('2015-10-10'));
  
  //Expected output should be: "1 year, 4 months, 29 days".
  diffDate(new Date('2014-05-10'), new Date('2015-10-09'));
  
  //Expected output should be: "1 year, 3 months, 30 days".
  diffDate(new Date('2014-05-10'), new Date('2015-09-09'));
  
  //Expected output should be: "9 months, 27 days".
  diffDate(new Date('2014-05-10'), new Date('2015-03-09'));
  
  //Expected output should be: "1 year, 9 months, 28 days".
  diffDate(new Date('2014-05-10'), new Date('2016-03-09'));
  
  //Expected output should be: "1 year, 10 months, 1 days".
  diffDate(new Date('2014-05-10'), new Date('2016-03-11'));
  </code></pre>