Bootstrap datepicker disabling past dates without current date

前端 未结 20 2076
[愿得一人]
[愿得一人] 2020-11-27 04:55

I wanted to disable all past date before current date, not with current date. I am trying by bootstrap datepicker library \"bootstrap-datepicker\" and using following code:<

相关标签:
20条回答
  • 2020-11-27 05:39

    It depends on what format you put on the datepicker So first we gave it the format.

        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!
    
        var yyyy = today.getFullYear();
        if(dd<10){
            dd='0'+dd;
        } 
        if(mm<10){
            mm='0'+mm;
        } 
        var today = yyyy+'-'+mm+'-'+dd; //Here you put the format you want
    

    Then Pass the datepicker (depends on the version you using, could be startDate or minDate which is my case )

        //Datetimepicker
        $(function () {
            $('#datetimepicker1').datetimepicker({
                minDate: today, //pass today's date
                daysOfWeekDisabled: [0],
                locale: 'es',
                inline: true,
                format: 'YYYY-MM-DD HH:mm', //format of my datetime (to save on mysqlphpadmin)
                sideBySide: true
            });
        });
    
    0 讨论(0)
  • 2020-11-27 05:40

    You can use the data attribute:

    <div class="datepicker" data-date-start-date="+1d"></div>
    
    0 讨论(0)
  • 2020-11-27 05:40

    To disable past dates & highlight today's date:

    $(function () {
        $('.input-daterange').datepicker({
            startDate : new Date(),
            todayHighlight : true
        });
    });
    

    To disable future dates & highlight today's date:

    $(function () {
        $('.input-daterange').datepicker({
            endDate : new Date(),
            todayHighlight : true
        });
    });
    

    For more details check this out https://bootstrap-datepicker.readthedocs.io/en/latest/options.html?highlight=startdate#quick-reference

    0 讨论(0)
  • 2020-11-27 05:40

    to disable past date just use :

      $('.input-group.date').datepicker({
           format: 'dd/mm/yyyy',
           startDate: 'today'
      });
    
    0 讨论(0)
  • 2020-11-27 05:41

    The following worked for me

    $('.input-group.date').datepicker({
         format: 'dd/mm/yyyy',
         startDate: new Date()
    });
    
    0 讨论(0)
  • 2020-11-27 05:43
    var date = new Date();
    date.setDate(date.getDate()-1);
    
    $('#date').datepicker({ 
        startDate: date
    });
    
    0 讨论(0)
提交回复
热议问题