Check if date is in the past Javascript

前端 未结 4 555
一整个雨季
一整个雨季 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:36

    $('#datepicker').datepicker().change(evt => {
      var selectedDate = $('#datepicker').datepicker('getDate');
      var now = new Date();
      now.setHours(0,0,0,0);
      if (selectedDate < now) {
        console.log("Selected date is in the past");
      } else {
        console.log("Selected date is NOT in the past");
      }
    });
    
    
    

提交回复
热议问题