title: Using .date() in JS to calculate the difference between two dates, what am I doing wrong?
body: <p>Afternoon,</p>
  
  <p>I'm calculating the difference between two dates using JS. I am trying to get a result accurate to a second. I've been getting on very well with it, but noticed an issue. The first two dates shown below show a difference of 5 years, but as soon as I add one more year to the future date, it shows 5 years, 1 Day. Where is the extra day coming from? When the future date hits 2020, it adds another day into the result, this is a recurring pattern. Can someone enlighten me? I don't have any leap year calculations involved yet, I've put my code below:</p>
  
  <pre><code>$(document).ready(function(){
  
      var todaysDate = new Date('2010/11/24 23:00:00');   
      var futureDate = new Date('2020/11/24 22:59:00');
  
      calculateTime(todaysDate,futureDate);
  });
  
  function calculateTime(todaysDate,futureDate){  
      var difference = futureDate.getTime() - todaysDate.getTime(); 
  
      var years = Math.floor(difference/1000/60/60/24/365);
          difference -= years*1000*60*60*24*365;
  
      var days = Math.floor(difference/1000/60/60/24);
          difference -= days*1000*60*60*24;
  
      var hours = Math.floor(difference/1000/60/60);
          difference -= hours*1000*60*60;
  
      var minutes = Math.floor(difference/1000/60);
          difference -= minutes*60*1000;
  
      var seconds = Math.floor(difference/1000);
  
      var result = years + ' Years, ';
          result += days + ' Days, ';
          result += hours + ' Hours, ';
          result += minutes + ' Minutes, ';
          result += seconds + ' Seconds';
  
      $('#time').html(result)
   }
  </code></pre>