I want to disable the 2nd Saturday, 4th Saturday, Sunday and public holidays, throughout the year, using jQuery Calendar.
-
1http://stackoverflow.com/a/15400806/2270492, Have a look at this – Hemal Jan 01 '16 at 06:58
-
3Please write code what have you tried so far. – Parth Trivedi Jan 01 '16 at 06:59
-
@Hemal please read question it is for calender. – Parth Trivedi Jan 01 '16 at 07:00
-
http://www.codeproject.com/Questions/1067759/How-To-disable-nd-th-saturday-sunday-and-Holiday-d may help u or u can use datepicker to disable specific date using jquery – Dhara Jan 01 '16 at 07:04
-
I also suggest to use jQuery datepicker. – Hemal Jan 01 '16 at 07:07
-
@Hemal how we can use datepicker instead of calander. – Ankit Kathiriya Jan 01 '16 at 07:09
-
@AnkitKathiriya stackoverflow.com/a/15400806/2270492 – Hemal Jan 01 '16 at 07:10
-
@Hemal the my question is how we can use datepicker in place of calander. – Ankit Kathiriya Jan 01 '16 at 07:12
-
@AnkitKathiriya include js file in html and $(selectedID).datepicker({//disable date logic}); – Dhara Jan 01 '16 at 07:13
2 Answers
Jquery Calendar plugin provide you a option "beforeShowDay", you can find more information on DataPickerUI
To Disable 2nd Saturday & 4th Saturday, you need to first calculate the sat or sunday of specific month then disable those dates, like we did for others calendars
sample code calculate sat & sunday https://www.hscripts.com/scripts/JavaScript/second-fourth.php
Created plunker for you, https://plnkr.co/edit/inBYY748BptaCd7Ulwwg?p=preview
//To disable Sundays you need to find out the Day of current date.
$(function () {
var publicHolidays = [
[11, 28, 2015],
[11, 30, 2015]
];
$("#datepicker").datepicker({
beforeShowDay: function (date) {
var day = date.getDay();
return [(day !== 0), ''];
}
});
//To disable public holidays create an array with you holiday list then
//return false when you browse calender.
$("#datepicker2").datepicker({
beforeShowDay: function (date) {
for (i = 0; i < publicHolidays.length; i++) {
if (date.getMonth() == publicHolidays[i][0] &&
date.getDate() == publicHolidays[i][1] &&
date.getFullYear() == publicHolidays[i][2]) {
return [false];
}
}
return [true];
}
});
});

- 21
- 4
For what it's worth, here's a couple of functions for the second/fourth Saturday part of the problem.
Both functions accept an instance of javascript Date()
and return true
or false
. You can use either one.
function is2ndOr4thSat_1(date) {
var day = date.getDay(),
week = Math.floor(date.getDate() / 7);
return day == 6 && (week == 1 || week == 3)
}
Hopefully is2ndOr4thSat_1()
is self explanatory.
function is2ndOr4thSat_2(date) {
var d = date.getDate(),
offset = (((1 + date.getDay() - d) % 7) + 7) % 7;
return !((offset + d) % 14);
}
is2ndOr4thSat_2()
is more obscure.
The expression (((1 + date.getDay() - d) % 7) + 7) % 7
finds the offset of the first of the month from a nominal zero (the 1st's preceding Saturday), using a true modulo algorithm that caters for negative numbers.
Then (offset + d) % 14
returns 0
if date
is either 14 or 28 days ahead of the nominal zero, and !
converts to a boolean of the required sense (true
for qualifying Saturdays otherwise false
).

- 19,138
- 5
- 33
- 44