I stumbled upon this function that calculates the difference between two dates in business days by excluding weekends (source: ):
function calculateBusinessDays(startDate, endDate)
{
if (endDate < startDate)
return 0;
var millisecondsPerDay = 86400 * 1000;
startDate.setHours(0,0,0,1);
endDate.setHours(23,59,59,999);
var diff = endDate - startDate;
var days = Math.ceil(diff / millisecondsPerDay);
var weeks = Math.floor(days / 7);
var remainingDays = days - (weeks * 2);
var startDay = startDate.getDay();
var endDay = endDate.getDay();
if (startDay - endDay > 1)
remainingDays = remainingDays - 2;
if (startDay == 0 && endDay != 6)
remainingDays = remainingDays - 1;
if (endDay == 6 && startDay != 0)
remainingDays = remainingDays - 1;
return remainingDays;
}
Could someone please guide me on how to pass two dates when calling this function? The dates will be variables in the YYYY-MM-DD format.
Thank you for any assistance, Tim