disable past dates on datepicker

前端 未结 22 1192
梦毁少年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:37

    Note: This scripts works when you're using the daterangepicker library. If you want to disable the Sat or Sunday date on daterangepicker then put this line of code.

            $("#event_start").daterangepicker({
                // minDate: new Date(),
                minYear: 2000,
                showDropdowns: true,
                singleDatePicker: true,
                timePicker: true,
                timePicker24Hour: false,
                timePickerIncrement: 15,
                drops:"up",
                isInvalidDate: function(date) {
                    //return true if date is sunday or saturday
                    return (date.day() == 0 || date.day() == 6);
                },
                locale: {
                    format: 'MM/DD/YYYY hh:mm A'
                }
            });
    

    OR if you want to disable the previous date also with sat and sun then uncomment the this line minDate: new Date()

    0 讨论(0)
  • 2020-11-29 06:40
    $("#datetimepicker2").datepicker({ 
      dateFormat: "mm/dd/yy", 
      minDate: new Date()
    });
    
    0 讨论(0)
  • 2020-11-29 06:41
    var dateToday = new Date();
    
    $('#datepicker').datepicker({                                     
        'startDate': dateToday
    });
    
    0 讨论(0)
  • 2020-11-29 06:42

    this works for me,

    $(function() { $('.datepicker').datepicker({ startDate: '-0m', autoclose: true }); });

    0 讨论(0)
提交回复
热议问题