We help IT Professionals succeed at work.
Get Started

Exclude holidays when counting days in jQuery datepicker range

peps03 asked
Last Modified: 2012-07-02

This piece of code reduces the weekends from a range of selected days in jQuery datepicker:

var start = new Date($("#startdate").val().split("/").reverse().join(","));
var end = new Date($("#enddate").val().split("/").reverse().join(","));

var weekend_count = 0;
for (i = start.valueOf(); i <= end.valueOf(); i+= 86400000){
	var temp = new Date(i);
	if (temp.getDay() == 0 || temp.getDay() == 6) {
$("#days").val((end - start) / 86400000 + 1 - weekend_count);        

Open in new window

I would like to alter it so also specific holidays that fall within the selected range are reduced:
var currentYear = (new Date).getFullYear();
var disabledDays = ["1-1-"+currentYear,"25-12-"+currentYear,"26-12-"+currentYear];

Open in new window

How should i alter the code?
Watch Question
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE