I am trying to calculate the number of working hours in a month to display on my website. I have managed to figure out how to get the days to display but its just getting the hours for different months considering that some months have 31,30 and 28/29 days.
function getBusinessDatesCount(startDate, endDate) {
var count = 0;
var curDate = startDate;
while (curDate <= endDate) {
var dayOfWeek = curDate.getDay();
if(!((dayOfWeek == 6) || (dayOfWeek == 0)))
count++;
curDate.setDate(curDate.getDate() + 1);
}
return count;
}
Usage:
var startDate = new Date('7/01/2015');
var endDate = new Date('7/31/2015');
var numOfDates = getBusinessDatesCount(startDate,endDate);
$('div#result').text(numOfDates);