title: Get the difference in months between two dates in (mm/dd/yyyy) format using jquery
body: <p>I was wanting to retrieve the month differences between two dates that a user enters in using the bootstrap datepicker. Along with this I am also trying to replace the second value (date2) to what the difference in months is when the user clicks the calculate button. When trying to work on this my code does not seem to be working...</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>$('#clickMe').click(function() {
      var date1 = $('#firstPayDate');
      var date2 = $('#loanTrm');
      var timeDiff = Math.abs(date2.getTime() - date1.getTime());
      var diffMonths = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
      date2.val(date2.val().replace(diffMonths));
  });
  </code></pre>
  
  <p>Here is a picture demonstration of what I am trying to accomplish:</p>
  
  <p><a href="https://i.stack.imgur.com/xpF6X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xpF6X.png" alt="enter image description here"></a></p>
  
  <p>I am trying to take the difference between these two entries (Maturity Date - First payment date)</p>
  
  <p><a href="https://i.stack.imgur.com/QC5iK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QC5iK.png" alt="enter image description here"></a>
  I am trying to get the calculations to occur once the user clicks the Calculate button, the difference in months gets replaced with the value that was entered in Maturity Date.</p>
  
  <p>Any help will be greatly appreciated!</p>