I'm trying to show a list of start dates but for some reason my function only seems to show dates from this year and not any from 2016. I've added the code below along with a jsfiddle link. Any help with this would be great, I've been looking everywhere on how to get this to work but have found anything that can help with next years dates.
HTML
<div id="date"></div>
jQuery
var availableDates = ["25-12-2015", "02-01-2016"];
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) != -1) {
return [true, "", "Available"];
} else {
return [false, "", "unAvailable"];
}
console.log(dmy, availableDates);
}
var lastDate = new Date("2016-10-31");
$('#date').datepicker({
dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
firstDay: 1,
beforeShowDay: available,
minDate: "-0M",
maxDate: lastDate
});
jsfiddle
The problem is getDate() for the 2nd would return 2 instead of 02. And the same with getMonth().
Either change your availableDates to:-
var availableDates = ["25-12-2015", "2-1-2016"];
or replace dmy like so:-
dmy = ("0" + date.getDate()).slice(-2) + "-" + ("0" + (date.getMonth()+1)).slice(-2) + "-" + date.getFullYear();
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With