JSFiddle - React, Tailwind, and code Playground

by Otobong Okoko

HTML

<input type='text' id="lastAssimilationDate"/><br>
<input type='text' id="lastAssimilationDateOver"/>
<br>
Expected Amount:<br>
<input type="text" id="exAmt"/>
<!-- <button>press</button> -->
<br><br>
Value of Annuity: <small id="today"></small>

JavaScript

$( "#lastAssimilationDate" ).datepicker({
  yearRange: "-20:+100",
  changeMonth: true,
  changeYear: true,
  dateFormat: "d-M-y"
});



$( "#lastAssimilationDateOver" ).datepicker({
  yearRange: "-20:+100",
  changeMonth: true,
  changeYear: true,
  dateFormat: "d-M-y"
});


function monthDiff(d1, d2) {
    var months;
    months = (d2.getFullYear() - d1.getFullYear()) * 12;
    months -= d1.getMonth() + 0;
    months += d2.getMonth();
    return months <= 0 ? 0 : months;
}

$("#exAmt").keyup(function(){
    d1 = new Date($( "#lastAssimilationDate" ).val());
    d2 = new Date($( "#lastAssimilationDateOver").val());
    //alert(monthDiff(d1, d2));
    console.log(d1);
    console.log(d2);
    var td = monthDiff(d1, d2);
		document.getElementById("today").innerHTML = td;
});