Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tahafarooqui/e220f815defce803395af9bf94682045 to your computer and use it in GitHub Desktop.
Save tahafarooqui/e220f815defce803395af9bf94682045 to your computer and use it in GitHub Desktop.
Jquery datepicker restrict dates in second date field based on selected date in first date field
jQuery(".startDate").datepicker({
minDate: 0,
onSelect: function (selected) {
var dt = jQuery(this).datepicker("getDate");
dt.setDate(dt.getDate() + 1);
jQuery(".endDate").datepicker("option", "minDate", dt);
jQuery(".endDate").datepicker("option", "dateFormat", "dd.mm.yy");
jQuery(".endDate").datepicker("setDate", dt);
//Dateformat
jQuery(".startDate").datepicker("option", "dateFormat", "dd.mm.yy");
}
});
jQuery(".endDate").datepicker({
minDate: 0,
onSelect: function (selected) {
var dt = jQuery(this).datepicker("getDate");
dt.setDate(dt.getDate() - 1);
//Dateformat
jQuery(".endDate").datepicker("option", "dateFormat", "dd.mm.yy");
}
});
@tahafarooqui
Copy link
Author

tahafarooqui commented Sep 17, 2017

Note: Make sure, your date picker code should be in this code.

jQuery(document).ready(function(){

//Your Date picker Code

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment