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...
Here is what I have so far:
$('#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));
});
Here is a picture demonstration of what I am trying to accomplish:
I am trying to take the difference between these two entries (Maturity Date - First payment date)
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.
Any help will be greatly appreciated!
Below logic will get difference in months
(endDate.getFullYear()*12+endDate.getMonth())-(startDate.getFullYear()*12+startDate.getMonth())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With