i have created below function to get date difference between two dates.. pleas check it that its correct as well as how to find no of month (multiply by 30 or 31 ?) and year..
function days_between(date1, date2,datepart) {
// The number of milliseconds in one day
var ONE_DAY=0;
if ( datepart === undefined ) {
datepart = 'D';
}
if(datepart='Y')
{
ONE_DAY = 1000 * 60 * 60 * 24 * 30 *12
}
else if (datepart='M')
{
ONE_DAY = 1000 * 60 * 60 * 24 * 30
}
else
{
ONE_DAY = 1000 * 60 * 60 * 24 //for day
}
// Convert both dates to milliseconds
var date1_ms = date1.getTime()
var date2_ms = date2.getTime()
// Calculate the difference in milliseconds
var difference_ms = Math.abs(date1_ms - date2_ms)
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY)
}