var startDates = '18-01-2016,02-02-2016,13-04-2016';
var arrayAsDateObjects = convertStringToDateObject(startDates);
$('input').datepicker({
dateFormat: 'dd-mm-yy',
beforeShowDay: function (date) {
var array = startDates.split(',');
var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [array.indexOf(string) == -1]
},
onSelect: function (date) {
alert(findNextDisabledDateWithinMonth(date));
}
});
function findNextDisabledDateWithinMonth(date) {
var splitDate = date.split("-");
var selectedDate = new Date(splitDate[2], Number(splitDate[1]) - 1, splitDate[0]);
var nextDisabledDate = null;
$.each(arrayAsDateObjects, function (i, ele) {
if (selectedDate < ele) {
nextDisabledDate = ele;
return false;
}
});
return nextDisabledDate;
}
function convertStringToDateObject(dateString) {
var ls = [];
var array = dateString.split(',');
$.each(array, function (i, ele) {
var splitDate = ele.split("-");
var date = new Date(splitDate[2], Number(splitDate[1]) - 1, splitDate[0]);
ls.push(date);
});
// Sort the dates in ascending order
ls.sort(function (a, b) {
return a - b;
});
return ls;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.