26

Possible Duplicate:
Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?

I would like to disable certain days like every monday or every tuesday or every monday, thursday friday, etc. on a jQuery UI datepicker.

I tried to play with beforeShowDay, but that requires a specific date. I just want to disable an entire day of the week.

Update: Thanks for the suggested solutions, but they all work for specific dates. What if I wanted to disable every single Monday and Tuesday for the entire year. How would I do that?

Community
  • 1
  • 1
Amir
  • 2,249
  • 7
  • 34
  • 48

1 Answers1

63

You can ue the beforeShowDate option of the datepicker combined with Date.getDay() to do what you want, like this:

​$("#datepicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 1 && day != 2)];
    }
})​​​​​;​

You can see a working demo here, this just takes the date, checks if it's a Monday (1) or Tuesday (2) and returns false for the first array entry if that's the case.

mafafu
  • 1,226
  • 1
  • 17
  • 22
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • How can this be modified and be used with checkboxes? For example, user will have an option of 7 checkboxes - one for each day of the week with values for the according days, and if user checks off just Monday, and then clicks on datepicker field, to show mondays only, and if they select/add/check more, then more days will be enabled in datepicker? – Xander Aug 07 '13 at 21:44
  • @Xander look at this http://codepen.io/anon/pen/XmQrPY – Sebastián Rojas Nov 20 '15 at 02:29
  • @SebastiánRojas Thank you :) Will come in handy again – Xander Nov 20 '15 at 18:21
  • `getUTCDay` should be used for localization purposes. In some parts of the world, Monday is the start of the week. – Zenkylo May 28 '19 at 14:27
  • this doesnt work in mine it gives a date picker but i can pick anydate – gangothri Jun 09 '22 at 11:47