Count Business Days

Count Business Days

From
Facebook
Status
Updating
Share
Entries

Business Days

⚠️
Includes end date in the calculation and does not exclude public holidays.
(prop("Start") < prop("End")) ? (ceil(dateBetween(prop("End"), prop("Start"), "hours") / 24) - floor(ceil(dateBetween(prop("End"), prop("Start"), "hours") / 24) / 7) * 2 + ((toNumber(formatDate(prop("Start"), "d")) - toNumber(formatDate(prop("End"), "d")) >= 1) ? (-2) : 0) + (and(toNumber(formatDate(prop("Start"), "d")) == 0, toNumber(formatDate(prop("End"), "d")) != 6) ? (-1) : 0) + (and(toNumber(formatDate(prop("End"), "d")) == 6, toNumber(formatDate(prop("Start"), "d")) != 0) ? (-1) : 0) + ((toNumber(formatDate(prop("Start"), "d")) - toNumber(formatDate(prop("End"), "d")) == -6) ? (-2) : 0) + 1) : toNumber("")
 

Testing

Entries

Reference

Separate Calculations
JS Examples
function workingDaysBetweenDates(d0, d1) { var startDate = parseDate(d0); var endDate = parseDate(d1); // Validate input if (endDate < startDate) return 0; // Calculate days between dates var millisecondsPerDay = 86400 * 1000; // Day in milliseconds startDate.setHours(0,0,0,1); // Start just after midnight endDate.setHours(23,59,59,999); // End just before midnight var diff = endDate - startDate; // Milliseconds between datetime objects var days = Math.ceil(diff / millisecondsPerDay); // Subtract two weekend days for every week in between var weeks = Math.floor(days / 7); days = days - (weeks * 2); // Handle special cases var startDay = startDate.getDay(); var endDay = endDate.getDay(); // Remove weekend not previously removed. if (startDay - endDay > 1) days = days - 2; // Remove start day if span starts on Sunday but ends before Saturday if (startDay == 0 && endDay != 6) days = days - 1 // Remove end day if span ends on Saturday but starts after Sunday if (endDay == 6 && startDay != 0) days = days - 1 return days; } function parseDate(input) { // Transform date from text to date var parts = input.match(/(\d+)/g); // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]]) return new Date(parts[0], parts[1]-1, parts[2]); // months are 0-based }
function workday_count(start,end) { var first = start.clone().endOf('week'); // end of first week var last = end.clone().startOf('week'); // start of last week var days = last.diff(first,'days') * 5 / 7; // this will always multiply of 7 var wfirst = first.day() - start.day(); // check first week if(start.day() == 0) --wfirst; // -1 if start with sunday var wlast = end.day() - last.day(); // check last week if(end.day() == 6) --wlast; // -1 if end with saturday return wfirst + days + wlast; // get the total }
function addWeekdays(date, days) { date = moment(date); // use a clone while (days > 0) { date = date.add(1, 'days'); // decrease "days" only if it's a weekday. if (date.isoWeekday() !== 6 && date.isoWeekday() !== 7) { days -= 1; } } return date; }
 
By Ben  •  Latest  •  Was this helpful? Please consider buying me a coffee. Cheers!By Ben  •  Latest  •  Was this helpful? Please consider buying me a coffee. Cheers!
By BenLatest • Was this helpful? Please consider buying me a coffee. Cheers!