0

I want to disable all next Mondays from jQuery datepicker except the one.

My actual code just disable all next Mondays :

function DisableDates(d) {
    var day = d.getDay();
    return [(day != 0)];
}

http://jsfiddle.net/infinityweb/q48pawj6/10/

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Suzan
  • 85
  • 7
  • it will be way more easy to use a datepicker that implements moment library, if not u could check for the current weeknumber and compare it https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php and return true if day == 1 and weeknumber = cur_weeknumber +1 – john Smith Jul 18 '21 at 11:25
  • 1
    @johnSmith That's a big library to require for a fairly trivial native calculation. Even the moment docs are now suggesting using smaller modularized libraries – charlietfl Jul 18 '21 at 12:19

1 Answers1

2

Here is an working example

http://jsfiddle.net/aswinkumar863/dsyk7ah0/

function DisableDates(d) {
  var day = d.getDay();
  var monday = new Date()
  monday.setHours(0, 0, 0, 0)
  monday.setDate(monday.getDate() + (1 + 7 - monday.getDay()) % 7)
  return [(monday.getTime() == d.getTime() || day != 1)];
}

$('#single-listing-date-range').datepicker({
  minDate: +1,
  beforeShowDay: DisableDates
});
User863
  • 19,346
  • 2
  • 17
  • 41