Sikander
Sikander

Reputation: 2835

Disable dates further than 2 days from current date in Datepicker

I am using jQuery UI DatePicker. I want to disable dates after 2 days from current date. How can I do that?

$(function() {
  $("#datepicker").datepicker();
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="form-group">
  <input type="text" id="datepicker" class="form-control" />
</div>

Upvotes: 1

Views: 828

Answers (2)

Feras Al Sous
Feras Al Sous

Reputation: 1083

You can use this code:

$(function() {
  $("#datepicker").datepicker({
    maxDate: '+2'
  });
});

Upvotes: 1

Rory McCrossan
Rory McCrossan

Reputation: 337560

To achieve this you can use the maxDate property. Providing +2 will give a value 2 days from the current. Try this:

$(function() {
  $("#datepicker").datepicker({
    maxDate: '+2'
  });
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div class="form-group">
  <input type="text" id="datepicker" class="form-control" />
</div>

Upvotes: 3

Related Questions