Skip to content

Commit a2cc679

Browse files
authored
Create script.js
1 parent 69c730d commit a2cc679

File tree

1 file changed

+18
-0
lines changed
  • Server-Side Components/Script Includes/Calculate Business days dynamically

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Function to add any number of business days to a given date
2+
function add_business_days(date, num_days) {
3+
var result_date = new GlideDateTime(date);
4+
var added_days = 0;
5+
6+
while (added_days < num_days) {
7+
result_date.addDaysUTC(1);
8+
var day_of_week = result_date.getDayOfWeekUTC();
9+
if (day_of_week != 6 && day_of_week != 7) { // Skip Saturday (6) and Sunday (7)
10+
added_days++;
11+
}
12+
}
13+
14+
return result_date.getDate();
15+
}
16+
17+
// Example usage:
18+
gs.print(add_business_days('2025-10-24 12:00:00', 5)); // Adds 5 business days

0 commit comments

Comments
 (0)