//Time Diffrence and logics

function ontimefrom() {
    var currentTime = new Date();
    var timefrom = Xrm.Page.getAttribute( "new_timefrom").getValue();
    //alert(currentTime);
    //alert(timefrom);
    diff(timefrom, currentTime);
}

function diff(timefrom, currentTime) {
    //debugger;
    var one_hour = 1000 * 60 * 60;
    var starttime = currentTime.getTime();
    var endtime = timefrom.getTime();
    //alert(starttime);
    //alert(endtime);

    var difference = (parseInt(starttime, 10) - parseInt(endtime, 10));
    //alert(difference);
    var hour;
    hour = difference / one_hour;
    //alert(hour);
    if (parseInt(hour, 10) <= 0) {
        alert( "Date should be Less than Current Date" );
        Xrm.Page.getAttribute( "new_timefrom").setValue(null );
        Xrm.Page.ui.controls.get( "new_timeto").setDisabled(true );
    }
    else {
        Xrm.Page.ui.controls.get( "new_timeto").setDisabled(false );
    }
}





function ontimeto() {
    var currentTime = new Date();
    var timefrom = Xrm.Page.getAttribute( "new_timefrom").getValue();
    var timeto = Xrm.Page.getAttribute( "new_timeto").getValue();

    //alert(timefrom);
    //alert(timeto);
    //totalnoofhours(timefrom,timeto);
    datedifference(timeto, timefrom);
    currenttimediff(timeto, currentTime)
}

function datedifference(timeto, timefrom) {
    //count No of hours

    var one_hour = 1000 * 60 * 60;
    var starttime = timefrom.getTime();
    var endtime = timeto.getTime();
    //alert(starttime);
    //alert(endtime);
    var difference = (parseInt(endtime, 10) - parseInt(starttime, 10));
    //alert(difference);
    var hour;
    hour = difference / one_hour;
    //alert(hour);
    if (parseInt(hour, 10) <= 0) {
        alert( "Time should be greater than selected Time" );
        // Xrm.Page.getAttribute("new_timeto").setValue(null);
    }
}

function currenttimediff(timeto, currentTime) {
    //debugger;
    var one_hour = 1000 * 60 * 60;
    var starttime = currentTime.getTime();
    var endtime = timeto.getTime();
    //alert(starttime);
    //alert(endtime);

    var difference = (parseInt(starttime, 10) - parseInt(endtime, 10));
    //alert(difference);
    var hour;
    hour = difference / one_hour;
    //alert(hour);
    if (parseInt(hour, 10) <= 0) {
        alert( "Date should be Less than Current Date" );
        Xrm.Page.getAttribute( "new_timeto").setValue(null );
    }

}
  



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