Excluding holidays in business-day date calculation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
28m ago - last edited 17m ago
Hi Community, good day
I’m using an onChange client script that calculates two future dates (35 business days and 90 business days) based on a selected date, and it already excludes weekends. Now I need to update this script so it also excludes US holidays during the calculation. Can someone guide me on how to properly modify or improve the script to handle holiday exclusion as well?
I am using this
function onChange(control, oldValue, newValue) {
if (!newValue) return;
var base = new Date(newValue);
if (isNaN(base.getTime())) return;
function calc(d, x) {
var r = new Date(d);
var c = 0;
while (c < x) {
r.setDate(r.getDate() + 1);
var k = r.getDay();
if (k != 0 && k != 6) c++;
}
return r.toISOString().split('T')[0];
}
var dA = calc(base, 35);
var dB = calc(base, 90);
g_form.setValue('dat2_35', dA);
g_form.setValue('dat2_90', dB);
}
thanks in Advance
