Its easy to find the month difference in Java since java supports calendar objects.
But java script supports Date objects but not calendar objects.
Here is a code for finding the month difference in javascript.
function getMonthsDifference(firstDate,lastDate)
{
var date1DtParse = Date.parse(lastDate);
var date2DtParse = Date.parse(firstDate);
var date1 = new Date(date1DtParse);
var date2 = new Date(date2DtParse);
var diffYears = date2.getFullYear()-date1.getFullYear();
var diffMonths = date2.getMonth()-date1.getMonth();
var diffDays = date2.getDate()-date1.getDate();
var months = (diffYears*12 + diffMonths);
if(diffDays>0)
{ months += '.'+diffDays; }
else if(diffDays<0)
{ months--;
months += '.'+(new Date(date2.getFullYear(),date2.getMonth(),0).getDate()+diffDays);
}
return months;
}
But java script supports Date objects but not calendar objects.
Here is a code for finding the month difference in javascript.
function getMonthsDifference(firstDate,lastDate)
{
var date1DtParse = Date.parse(lastDate);
var date2DtParse = Date.parse(firstDate);
var date1 = new Date(date1DtParse);
var date2 = new Date(date2DtParse);
var diffYears = date2.getFullYear()-date1.getFullYear();
var diffMonths = date2.getMonth()-date1.getMonth();
var diffDays = date2.getDate()-date1.getDate();
var months = (diffYears*12 + diffMonths);
if(diffDays>0)
{ months += '.'+diffDays; }
else if(diffDays<0)
{ months--;
months += '.'+(new Date(date2.getFullYear(),date2.getMonth(),0).getDate()+diffDays);
}
return months;
}