disable past dates on datepicker

前端 未结 22 1326
梦毁少年i
梦毁少年i 2020-11-29 06:03

How to disable past dates from the current date on a datetimepicker? I tried few posts for similar question but was unable to achieve it, Below is what I tried



        
22条回答
  •  余生分开走
    2020-11-29 06:25

    If you want to set date on page load then use this:

     $('#datetimepicker1').datetimepicker({
      minDate: new Date()
      });
    

    This will set today's date as start date on page load itself and disable all the previous dates.
    But if you want to set date on click of particular text-box instead of setting it on page load then use this: $('#datetimepicker1').datetimepicker(); $("#datetimepicker1").on("click", function (e) { $('#datetimepicker1').data("DateTimePicker").minDate(new Date()); });

    In place of new Date(), we can use any string specifying Date in a format specified by us if we don't want to set current date as minimum date. e.g:

    $('#datetimepicker1').data("DateTimePicker").minDate("10/15/2018");
    

提交回复
热议问题