user8317974
user8317974

Reputation:

Disable all dates after specific date in jQuery datetimepicker

$(function() {
  $("#datepicker").datepicker({
    maxDate: new Date()
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<link data-require="jqueryui@*" data-semver="1.10.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/css/smoothness/jquery-ui-1.10.0.custom.min.css" />

<script data-require="jqueryui@*" data-semver="1.10.0" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script>
<p>Date: <input type="text" id="datepicker" /></p>

I have a jquery datepicker where I want the max date to be Sep 29'2017. Right now, it's today's date. Any help would be appreciated.

Thank you.

Upvotes: 1

Views: 3380

Answers (2)

Souvik Ghosh
Souvik Ghosh

Reputation: 4606

This will work

$(function() {
  $("#datepicker").datepicker({
    maxDate: new Date(2017, 8, 29)  //you can provide any future date here
  });
});

example:-

$( "#datepicker" ).datepicker({
  maxDate: new Date(2017, 8, 29)
});
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="datepicker">

Upvotes: 1

Shiladitya
Shiladitya

Reputation: 12181

Here you go with a solution https://jsfiddle.net/5pct45bt/

$( "#datepicker" ).datepicker({
  maxDate: new Date(2017, 8, 29)
});
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="datepicker">

You can also use +1D for adding 1day plus today.

Hope this will help you.

Upvotes: 0

Related Questions