Calculate number of days between two dates minus weekends

Fungus1487

I browsed google and found nothing so thought i would put my efforts up here.
hope this all helps.

this function will allow you to return the number of days between two dates minus saturdays and sundays. (including the start date)

2,261 Views
About the Author
// ########## startMonth and endMonth both start at 0 i.e 0 = january, 1 = feb etc
function getDaysMinusWeekend(startDay, startMonth, startYear, endDay, endMonth, endYear) {
	var sdate = new Date();
	var edate = new Date();
	var odays = 0;
	var total = 0;

	sdate.setFullYear(startYear,startMonth,startDay);
	edate.setFullYear(endYear,endMonth,endDay);

	odays = 6 - sdate.getDay();
	if(odays == 6) {
		odays = 0;
	}

	sdate.setFullYear(startYear,startMonth,startDay + odays);

	return Math.floor(((((edate.getTime() - sdate.getTime()) / 1000 / 60 / 60 / 24) / 7) * 5) + 

odays);
}
achelalsharma 0 Newbie Poster

Nice code works fine

manay 0 Newbie Poster

Hi, is there a possibility for the public holidays to be excluded as well aside from weekeds? Thank you.

pritaeas 2,045 Most Valuable Poster Moderator Featured Poster

Yes, it's possible, but then you'll need a lookup table containing those dates

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.