function onjoiningdate()
{
//get the value of date of joining
var startday=Xrm.Page.getAttribute("new_joiningdate").getValue();

var today=new Date();
var one_day=1000*60*60*24;
var one_month=30;
var one
var starttime=startday.getTime();
var currenttime=today.getTime();
//alert(starttime);
//alert(currenttime);
var difference = Math.abs(currenttime - starttime);
//alert(difference);
noofdays=Math.round(difference/one_day)
noofmonths=Math.round(noofdays/one_month);
//alert(noofdays);
//alert(noofmonths);
Xrm.Page.getAttribute("new_loyaltyduration").setValue(noofmonths);
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012