Hello , below you will find function calculating difference in days between two field using java script .

function diffrenceindays() {
    var startdate = GetDateValue(startfield);
    var Enddate = GetDateValue(endfield);

    var oneday = 1000 * 60 * 60 * 24;
    var differenceInDays = ((Enddate - startdate) / oneday);
    if (differenceInDays < 0) {
        alert(" date cannot be less then start date");

    }
    alert(" diffrence in days  " + differenceInDays);

}

function GetDateValue(field) {


    var year = field.getFullYear();
    var month = field.getMonth();
    var day = field.getDate();
    dateOnly = new Date(year, month, day);
    return dateOnly;


}





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