0

I am working on a datepicker that will disable all the selection when the day falls on Friday & Saturday.

I've already created a datepicker that will only select next week's date (with the help of the other member here).

var date = new Date();
var weekday = date.getDay();
var daysTillWeekOver = 7 - weekday;

var dateMax = `+${daysTillWeekOver}d`;

var dateMin = new Date(Date.now()); 
dateMin.setDate(dateMin.getDate());


$(".datepicker").datepicker({
  minDate: dateMax,
  maxDate: daysTillWeekOver + 6
}); 

I want all the dates on my datepicker will be disabled once the day in the current week falls every Friday and Saturday.

rrk
  • 15,677
  • 4
  • 29
  • 45
  • Possible duplicate of [Disable specific days of the week on jQuery UI datepicker](https://stackoverflow.com/questions/2968414/disable-specific-days-of-the-week-on-jquery-ui-datepicker) – Lelio Faieta May 28 '19 at 13:41
  • It's not duplicate for the said topic. Because currently the code above will enable the dates for next week but when the day fall on Friday and Saturday of the current week all dates will be disabled. – Julius Ticong May 28 '19 at 13:59

2 Answers2

0

Here's a modified solution based on Lelio's comment.

$(function() {
  var now = new Date();
  var currentDayOfTheWeek = now.getUTCDay()
  $("#datepicker").datepicker({
    beforeShowDay: function(date) {
      return [currentDayOfTheWeek != 5 && currentDayOfTheWeek != 6, ""];
    }
  });
});

Basically, if the current day of the week is Friday or Saturday, the days on the calendar will be disabled.

Zenkylo
  • 136
  • 6
0

Thanks for the answer above but that's not work for me. Here's what I did and solved my problem. (with the help of Grant Noe).

var date = new Date();
var weekday = date.getDay();
var daysTillWeekOver = 7 - weekday;

var dateMax = `+${daysTillWeekOver}d`;

var dateMin = new Date(Date.now()); 
dateMin.setDate(dateMin.getDate());
var weekdayCheck = dateMin.getDay();

if (weekdayCheck == 5 || weekdayCheck == 6) {
var maxD = 0;
}
else{
var maxD = daysTillWeekOver + 6;
}

// activate datepicker
$(".datepicker").datepicker({

  minDate: dateMax,
  maxDate:  maxD
});