Bootstrap datepicker disabling past dates without current date

前端 未结 20 2097
[愿得一人]
[愿得一人] 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:26

    use

    startDate: '-0d'
    

    Like

    $("#datepicker").datepicker({
        startDate: '-0d',
        changeMonth: true
    });
    
    0 讨论(0)
  • 2020-11-27 05:26

    Please refer to the fiddle http://jsfiddle.net/Ritwika/gsvh83ry/

    **With three fields having date greater than the **
    <input type="text" type="text" class="form-control datepickstart" />
    <input type="text" type="text" class="form-control datepickend" />
    <input type="text" type="text" class="form-control datepickthird" />
    
    var date = new Date();
     date.setDate(date.getDate()-1);
    $('.datepickstart').datepicker({
     autoclose: true,
     todayHighlight: true,
     format: 'dd/mm/yyyy',
      startDate: date
    });
    $('.datepickstart').datepicker().on('changeDate', function() {
        var temp = $(this).datepicker('getDate');
        var d = new Date(temp);
      d.setDate(d.getDate() + 1);
      $('.datepickend').datepicker({
     autoclose: true,
     format: 'dd/mm/yyyy',
     startDate: d
    }).on('changeDate', function() {
        var temp1 = $(this).datepicker('getDate');
        var d1 = new Date(temp1);
       d1.setDate(d1.getDate() + 1);
      $('.datepickthird').datepicker({
     autoclose: true,
     format: 'dd/mm/yyyy',
     startDate: d1
    });
    });
    });
    
    0 讨论(0)
  • 2020-11-27 05:28

    If your requirement is to disable the startDate and endDate dynamically based on one on another you can you this.

    $('#date2').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true
            }).on('show', function(e){
                var date = $('#date3').datepicker('getDate');
                if(date){
                 $('#date2').datepicker('setEndDate', date);
                    }
        });
    
            $('#date3').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true
            }).on('show', function(e){
                var date = $('#date2').datepicker('getDate');
                if(date){
                 $('#date3').datepicker('setStartDate', date);
                    }
        });
    

    If your requirement is just disabled past dates then you can use below snippet.

    $('#date2').datepicker({
                todayHighlight: true,
                autoclose: true,
                format: "dd/mm/yyyy",
                clearBtn : true,
                startDate : new Date()
            })
    

    If your requirement is just disabled future dates then you can use below snippet.

     $('#date2').datepicker({
                    todayHighlight: true,
                    autoclose: true,
                    format: "dd/mm/yyyy",
                    clearBtn : true,
                    endDate : new Date()
                })
    

    I hope it will help someone.

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

    var nowDate = new Date();
    var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);
    	$('#date').datetimepicker({
    		startDate: today
    	});

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

    Use minDate

    var date = new Date();
    var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
    
    $('#date').datepicker({ 
        minDate: today
    });
    
    0 讨论(0)
  • 2020-11-27 05:39

    The solution is much simpler:

    $('#date').datepicker({ 
        startDate: "now()" 
    });
    

    Try Online Demo and fill input Start date: now()

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