Skip to content

Instantly share code, notes, and snippets.

@simonpioli
Created March 16, 2013 20:16
Show Gist options
  • Save simonpioli/5178132 to your computer and use it in GitHub Desktop.
Save simonpioli/5178132 to your computer and use it in GitHub Desktop.
Date-pickers to show between 2 dates using jQuery UI Datepicker
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
numberOfMonths: 1,
beforeShow: function( ) {
var other = this.id == "from" ? "#to" : "#from";
var option = this.id == "from" ? "maxDate" : "minDate";
var selectedDate = $(other).datepicker('getDate');
$(this).datepicker( "option", option, selectedDate );
}
}).change(function(){
var other = this.id == "from" ? "#to" : "#from";
if ( $('#from').datepicker('getDate') > $('#to').datepicker('getDate') )
$(other).datepicker('setDate', $(this).datepicker('getDate') );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment