JSFiddle - React, Tailwind, and code Playground
HTML
start
<input class="start" />
<br/>end
<input class="end" />
<button value='calculate' class='hulk' >calculate</button>
JavaScript
$('.start,.end').datepicker();
$('.hulk').click(function () {
var sDate = $('.start').val();
var nDate = $('.end').val();
console.log(sDate); /* Logs Date {Wed Oct 16 2013 00:00:00 GMT+0200 (CEST)} */
console.log(nDate); /* Logs Date {Wed Oct 18 2013 00:00:00 GMT+0200 (CEST)} */
var startdate = new Date(sDate);
var enddate = new Date(nDate);
enddate.setDate(enddate.getDate() - startdate.getDate());
alert(monthDiff(startdate,enddate));
});
function monthDiff(d1, d2) {
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth();
return months <= 0 ? 0 : months;
}