Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Business Day Calculator for ServiceNow

This JavaScript function calculates a future date by adding a specified number of **business days** (excluding weekends) to a given date.


## Features
- Skips weekends (Saturday and Sunday)
- Works with any number of business days
- Uses ServiceNow's `GlideDateTime` API

## Usage
1. Copy the function into a **Script Include**, **Business Rule**, or **Scheduled Job** in ServiceNow.
2. Call the function with:
- A valid date string (e.g., `'2025-10-24 12:00:00'`)
- The number of business days to add (e.g., `5`)

## Example
```javascript
gs.print(add_business_days('2025-10-24 12:00:00', 5));
// Output: 2025-10-31 (skips weekend)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Function to add any number of business days to a given date
function add_business_days(date, num_days) {
var result_date = new GlideDateTime(date);
var added_days = 0;

while (added_days < num_days) {
result_date.addDaysUTC(1);
var day_of_week = result_date.getDayOfWeekUTC();
if (day_of_week != 6 && day_of_week != 7) { // Skip Saturday (6) and Sunday (7)
added_days++;
}
}

return result_date.getDate();
}

// Example usage:
gs.print(add_business_days('2025-10-24 12:00:00', 5)); // Adds 5 business days
Loading