jQuery Datepicker to Disable a Specific Date AND the previous day

jQuery Datepicker to Disable a Specific Date AND the previous day

Hello Forum,

Based on the posts I've found online, I have coded a BeforeShowDay function that disables specific dates I've added to an array. This is working fine. My next step is to modify the function so that the Datepicker automatically disables the next day of any date found in the array.

For example, if October 22 needs to be disabled (e.g. the lodge is fully booked that day), I need the Datepicker to automatically disable October 21 as well (as visitors are trying to book a 2-night visit, and they can't spend 2 nights if their 2nd night is fully booked). Does that make sense?

So far here's my code:

  1. var BookedList = new Array();
  2. BookedList.push("20121022");
  3. $(document).ready(function () {
  4.       $('.date').datepicker({
  5. dateFormat: 'yy-M-dd',
  6. minDate:2,
  7. maxDate:'+2Y',
  8. changeMonth: true,
  9. changeYear: true,
  10. firstDay: 1,
  11. beforeShowDay: function(dateToHide){
  12. return [!($.inArray($.datepicker.formatDate('yymmdd', dateToHide),BookedList) >= 0), ""]; 
  13. }
  14.       });
  15. }
My hunch is that I have to create a new array that loops through the BookedList array and for each entry, convert it to a date object, store its previous day in a new date variable, make that variable a dateString object, and add that record to the new array. Then, with the beforeShowDay function, only show the day if the date is not in either array. If that would work, any JS coders know the syntax for accomplishing that?

Thanks so much!
Mindy  :)