Karthick
Karthick

Reputation: 443

bootstrap datepicker js disable future dates

I want disable future dates only on bootstrap datepicker.I had tried but can't resolve this problem.Anybody help!

This is my code

ready = function(){
$('.datepicker').datepicker({
      format: 'mm-dd-yyyy',
      endDate: '+0d',
      autoclose: true
  });
};
$(document).ready(ready);
$(document).on('page:load', ready);

Upvotes: 2

Views: 19665

Answers (2)

Samuel Eli
Samuel Eli

Reputation: 1

The right thing to do is to declare a variable to hold the current date then use that in the code as the date. so below is what you need to do

    <script>
 var date = new Date();
        var d = new Date();        
        d.setDate(date.getDate());
    $(document).ready(function(){
    $('.datepicker').datepicker({
        format: 'mm-dd-yyyy',
        endDate: d,       
    });
});

</script>

With this, you are sure of what you want

Upvotes: 0

Ankush Jain
Ankush Jain

Reputation: 7049

try the following

$(document).ready(function(){
    $('.datepicker').datepicker({
        format: 'mm-dd-yyyy',
        endDate: '+0d',
        autoclose: true
    });
});

Upvotes: 4

Related Questions