with this Snippet i store the Array of dates between 2 dates in a variable "disabled" to disable the dates in a bootstrap datepicker.
var startdate1 = $(".startdate1").text();
var enddate1 = $(".enddate1").text();
var daysBetweenDates = function(startdate1, enddate1) {
var now = startdate1, dates = [];
while (now.isBefore(enddate1) || now.isSame(enddate1)) {
dates.push(now.format("\"D.M.YYYY\""));
now.add('days', 1);
}
return dates;
};
var fromDate = moment(startdate1,"DD.MM.YYYY");
var toDate = moment(enddate1,"DD.MM.YYYY");
var results = daysBetweenDates(fromDate, toDate).join(', ');
$('#results').html(results);
var disabled = results;
the output in frontend is: "15.2.2018", "16.2.2018", "17.2.2018", "18.2.2018", "19.2.2018", "20.2.2018", "21.2.2018", "22.2.2018", "23.2.2018", "24.2.2018", "25.2.2018", "26.2.2018"
the Bootstrap datepicker disables the dates only if the array of dates is hardcoded in my datepicker instance but not with the variable in it:
$('.bdates').datepicker({
format: "dd.mm.yyyy",
keyboardNavigation: false,
daysOfWeekDisabled: "2,3,4,5,6",
daysOfWeekHighlighted: "0,1",
calendarWeeks: true,
autoclose: true,
todayHighlight: true,
updateViewDate: false,
datesDisabled: disabled,
startDate: startdate,
endDate: enddate,
language: "de"
});
Have a look in this fiddle jsfiddle.net/8k1um9k9/
What is going wrong? Can someone give me please a solution?! thank you!