Check if date is in the past Javascript

前端 未结 4 547
一整个雨季
一整个雨季 2020-12-01 03:58

All, I\'m using the jQuery UI for the date picker. I\'m trying to check with javascript though that the date the user has entered is in the past. Here is my form code:

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 04:41

    function isPrevDate() {
        alert("startDate is " + Startdate);
        if(Startdate.length != 0 && Startdate !='') {
            var start_date = Startdate.split('-');
            alert("Input date: "+ start_date);
            start_date=start_date[1]+"/"+start_date[2]+"/"+start_date[0];
            alert("start date arrray format " + start_date);
            var a = new Date(start_date);
            //alert("The date is a" +a);
            var today = new Date();
            var day = today.getDate();
            var mon = today.getMonth()+1;
            var year = today.getFullYear();
            today = (mon+"/"+day+"/"+year);
            //alert(today);
            var today = new Date(today);
            alert("Today: "+today.getTime());
            alert("a : "+a.getTime());
            if(today.getTime() > a.getTime() )
            {
                alert("Please select Start date in range");
                return false;
            } else {
                return true;
            }
        }
    }
    

提交回复
热议问题