On
/// <reference path="XrmPage-vsdoc.js" />
function calMonths() {
    //get the startdate field value in variable
    var startday = xrm.page.getAttribute( "fieldname").getValue();
    // get todays date in variable
    var today = new date();
    // get the value of one day in (mili_second * second * min * hours)
    var one_dat = 1000 * 60 * 60 * 24;
    // get no of days in month
    var one_month = 30;
    //get time
    var starttime = startday.getTime();
    var currenttime = today.getTime();

    var diffrence = math.abs(currenttime - starttime);
    noofdays = Math.round(diffrence / one_day);
    noofmonths = Math.round(noofdays / one_month);
    // set the noofmonths value in field
    xrm.page.getAttribute( "new_calmonths").setValue(noofmonths);

}



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