Date Validation

page_init();
var dat = new Date();
var myNewDate = new Date(dat);
myNewDate.setDate(dat.getDate() + 90);
var newCurDOB = new Date(1940, 00, 00, 00, 00, 00, 00);
var newCurYear = new Date().getFullYear();
var dat = new Date();
myNewDate.setDate(dat.getDate() + 90);
var newCurDOB = new Date(1940, 00, 00, 00, 00, 00, 00);
var newCurYear = new Date().getFullYear();
$("#txtStart_Date").datepicker({
    orientation: "left",
    autoclose: !0,
    dateFormat: "yy-mm-dd",
    yearRange: '2019:' + (new Date().getFullYear() + 1),
    todayHighlight: true,
    changeMonth: true,
    changeYear: true,
    minDate: addDays(new Date(), 0),
    onSelect: function(selected) {
        var splitDate = selected.split("-");
        var newCurDate = new Date(splitDate[2], splitDate[1] - 1, splitDate[0]);
        $("#txtStart_Date").datepicker("option", "minDate", newCurDate);
        if ($("#txtEnd_Date").val() != '') {
            var splitEndDate1 = $('#txtEnd_Date').val().split("-");
            var EndDate1 = new Date(splitEndDate1[2], splitEndDate1[1] - 1, splitEndDate1[0]);
        }
    }
});
$("#txtEnd_Date").datepicker({
    orientation: "left",
    autoclose: !0,
    dateFormat: "yy-mm-dd",
    yearRange: '2019:' + (new Date().getFullYear() + 1),
    todayHighlight: true,
    changeMonth: true,
    changeYear: true,
    minDate: addDays(new Date(), 0),
    onSelect: function(selected) {
        if ($("#txtStart_Date").val() == '') {
            $("#txtEnd_Date").val('');
            swal({
                title: "Warning!",
                text: "Please select Start Date.",
                type: "",
                closeOnConfirm: true,
                confirmButtonText: "OK",
                confirmButtonClass: 'btn-primary',
                showLoaderOnConfirm: true,
            });
        } else {
            if ($("#txtStart_Date").val() > $("#txtEnd_Date").val()) {
                $("#txtEnd_Date").val('');
                swal({
                    title: "Warning!",
                    text: "Please Enter  Valid Date.",
                    type: "",
                    closeOnConfirm: true,
                    confirmButtonText: "OK",
                    confirmButtonClass: 'btn-primary',
                    showLoaderOnConfirm: true,
                });
            }
        }
    }
});

function DateFn() {
    var dat = new Date();
    var myNewDate = new Date(dat);
    myNewDate.setDate(dat.getDate() + 90);
    var newCurDOB = new Date(1940, 00, 00, 00, 00, 00, 00);
    var newCurYear = new Date().getFullYear();
    $("#txtStart_Date").datepicker({
        orientation: "left",
        autoclose: !0,
        dateFormat: "yy-mm-dd",
        yearRange: '2019:' + (new Date().getFullYear() + 1),
        todayHighlight: true,
        changeMonth: true,
        changeYear: true,
        onSelect: function(selected) {
            var splitDate = selected.split("-");
            var newCurDate = new Date(splitDate[2], splitDate[1] - 1, splitDate[0]);
            // $("#txtStart_Date").datepicker("option", "minDate", newCurDate);
            // if ($("#txtEnd_Date").val() != '') {
            // var splitEndDate1 = $('#txtEnd_Date').val().split("-");
            // var EndDate1 = new Date(splitEndDate1[2], splitEndDate1[1] - 1, splitEndDate1[0]);
            // }
        }
    });

    function getDate(dop) {
        var date = moment(new Date(moment(dop).toLocaleString().substr(0, 16)));
        return (date.format("yy-mm-dd"));
    }

    function addDays(theDate, days) {
        return new Date(theDate.getTime() + days * 24 * 60 * 60 * 1000);
    }

    function subDays(theDate, days) {
        return new Date(theDate.getTime() - days * 24 * 60 * 60 * 1000);
    }

    function CalculateDuration(date1, date2) {
        var diff = Math.floor(date2.getTime() - date1.getTime());
        var day = 1000 * 60 * 60 * 24;
        return (Math.floor(diff / day) + 1);
    }