Skip to content

Instantly share code, notes, and snippets.

@xeviknal
Last active August 29, 2015 14:18
Show Gist options
  • Save xeviknal/52687513fa8c7236bd20 to your computer and use it in GitHub Desktop.
Save xeviknal/52687513fa8c7236bd20 to your computer and use it in GitHub Desktop.
Disable ranges of time in jQuery DatePicker
var holidays = [ ['04/5/2015', '04/11/2015'], ['4/26/2015', '4/28/2015'], ['4/30/2015', '5/8/2015'] ];
function highlightDays(date) {
for (var i = 0; i < holidays.length; i++) {
var in_range = (new Date(holidays[i][0]) <= date) && (new Date(holidays[i][1]) >= date);
if (in_range) {
return [false];
}
}
return [true];
}
$(function () {
$("#dp").datepicker({
minDate: 0,
dateFormat: 'mm/dd/yy',
inline: true,
numberOfMonths: [1, 2],
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: highlightDays,
});
});
@xeviknal
Copy link
Author

xeviknal commented Apr 3, 2015

Improved a piece of code from http://jsfiddle.net/CxNNh/78/
Not focused on performance neither style!

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