Skip to content

Instantly share code, notes, and snippets.

@thomasthesecond
Last active December 14, 2015 16:49
Show Gist options
  • Save thomasthesecond/5117736 to your computer and use it in GitHub Desktop.
Save thomasthesecond/5117736 to your computer and use it in GitHub Desktop.
jQuery datepicker with arrival/departure fields.
// Arrival Field
$('input.datepicker.arrival').datepicker(
{
dateFormat: 'mm/dd/yy',
minDate: 0
});
// Departure Field
$('input.datepicker.departure').datepicker(
{
dateFormat: 'mm/dd/yy',
beforeShow: restrictDepartureDate
});
function restrictDepartureDate()
{
var arrivalDate = $('.arrival.datepicker').datepicker('getDate');
var arrivalDateYear = $.datepicker.formatDate('yy', arrivalDate);
var arrivalDateMonth = $.datepicker.formatDate('m', arrivalDate);
var arrivalDateDay = parseFloat($.datepicker.formatDate('d', arrivalDate));
$('input.datepicker.departure').datepicker('option', 'minDate', new Date(arrivalDateYear, arrivalDateMonth - 1, arrivalDateDay + 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment