21
rated 0 times
[
24]
[
3]
/ answers: 1 / hits: 36100
/ 9 Years ago, tue, february 10, 2015, 12:00:00
How to calculate the number of working days between two dates in JavaScript using moment.js. I have a working formula that calculate these days, but the formula does not satisfies all conditions:
here is my code:
var start= moment(data[x].start_date);
var end= moment(data[x].est_end_date);
var difference= end.diff(start, 'days');
var workingDays= Math.round((difference/7)*5);
//data[x] is for iterating over a loop
I get five days per 7 days here because saturday and sunday are considered as NON-Working days, but this formula will fail if the count of the days were started from sunday or saturday.
Please any one could help in this regard that what necessary changes must be done in order to avoid this problem.
More From » date