//ending Date Validation On starting Date Change
function endingDateValidation() {
    var startingDate = new Date(Xrm.Page.getAttribute("new_startingdate" ).getValue());
    var endingDate = new Date(Xrm.Page.getAttribute( "new_endingdate").getValue());
    var ExDate = Xrm.Page.getAttribute( "new_endingdate").getValue();
    if (ExDate != null) {
        if (startingDate.getYear() == endingDate.getYear()) {
            if ((startingDate.getMonth() + 1) == (endingDate.getMonth() + 1)) {
                if (startingDate.getDate() >= endingDate.getDate()) {
                    alert( "Please Enter Valid Starting Date" );
                    Xrm.Page.getAttribute( "new_startingdate").setValue(null );
                }
            }
            else if (startingDate.getMonth() > endingDate.getMonth()) {
                alert( "Please Enter Valid Starting Date" );
                Xrm.Page.getAttribute( "new_startingdate").setValue(null );
            }
        }
        else if (startingDate.getYear() >= endingDate.getYear()) {
            alert( "Please Enter Valid Starting Date" );
            Xrm.Page.getAttribute( "new_startingdate").setValue(null );
        }
    }
}



-------------------------------------------------------------------------------



function onfromdate() {
    currentTime = new Date();
    var currentmonth = currentTime.getMonth() + 1;
    var currentdate = currentTime.getDate();
    var currentyear = currentTime.getFullYear();
    //alert(currentdate );
    //alert(currentmonth );
    //alert(currentyear );
    var from = Xrm.Page.getAttribute( "new_fromdate").getValue();
    var fromdate = from.getDate();
    var frommonth = from.getMonth() + 1;
    var fromyear = from.getFullYear();
    //alert(fromdate );
    //alert(frommonth );
    //alert(fromyear );

    if (fromyear < currentyear) {
        alert( "Year should be greater than Current Year" );
        Xrm.Page.getAttribute( "new_fromdate").setValue(null );

    }


    else if (fromyear > currentyear) {

    }

    else if (fromyear = currentyear) {
        if (frommonth > currentmonth) {

        }
        else if (frommonth < currentmonth) {

            alert( "Month should be greater than Current Month" );
            Xrm.Page.getAttribute( "new_fromdate").setValue(null );

        }
        else if (frommonth = currentmonth) {
            if (fromdate > currentdate) {
                //  alert("if");
            }
            else if (fromdate < currentdate) {
                alert( "Date should be greater than Current Date" );
                Xrm.Page.getAttribute( "new_fromdate").setValue(null );

            }
        }

    }
}





---------------------------------------------------------------------------



function ontodate() {
    var from = Xrm.Page.getAttribute( "new_fromdate").getValue();
    var fromdate = from.getDate();
    var frommonth = from.getMonth() + 1;
    var fromyear = from.getFullYear();

    var to = Xrm.Page.getAttribute( "new_todate").getValue();
    var todate = to.getDate();
    var tomonth = to.getMonth() + 1;
    var toyear = to.getFullYear();




    if (toyear < fromyear) {
        alert( "Year should be greater than selected Year" );
        Xrm.Page.getAttribute( "new_todate").setValue(null );

    }


    else if (toyear > fromyear) {

    }

    else if (toyear = fromyear) {
        if (tomonth > frommonth) {

        }
        else if (tomonth < frommonth) {

            alert( "Month should be greater than selected Month" );
            Xrm.Page.getAttribute( "new_todate").setValue(null );

        }
        else if (tomonth = frommonth) {
            if (todate > fromdate) {
                //  alert("if");
            }
            else if (todate < fromdate) {
                alert( "Date should be greater than selected Date" );
                Xrm.Page.getAttribute( "new_todate").setValue(null );

            }
        }

    }
}


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