Calculate Business Days
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 08:11 AM
Hello Community,
I need to calculate 10 business days in the future from any given date. I'm using the script below but it is not counting business days, it is just counting 10 days out which is incorrect. How do I calculate the date 10 business days out?
getbusinessdays : function getbusinessdays(date, numberOfDays) {
var schedule = "968d3fbe1b35b3408ed610ad2d4bcbd";
var glideSchedule = new GlideSchedule();
glideSchedule.load(schedule);
var start = new GlideDateTime();
start.setDisplayValue(date);
var actualNumberOfDays = 0;
if(glideSchedule.isInSchedule(start)){
for(var x = 0; x < numberOfDays; x++){
start.addDays(1);
if(glideSchedule.isInSchedule(start)){
actualNumberOfDays++;
}
else{
if(start.getDayOfWeek() == 6){
start.addDays(2);
actualNumberOfDays++;
}
else if(start.getDayOfWeek() == 7){
start.addDays(1);
actualNumberOfDays++;
}
}
}
return start;
}
else{
if(start.getDayOfWeek() == 6){
start.addDays(2);
actualNumberOfDays++;
}
else if(start.getDayOfWeek() == 7){
start.addDays(1);
actualNumberOfDays++;
}
if(glideSchedule.isInSchedule(start)){
for(var y = 0; y < numberOfDays; y++){
start.addDays(1);
if(glideSchedule.isInSchedule(start)){
actualNumberOfDays++;
}
else{
if(start.getDayOfWeek() == 6){
start.addDays(2);
actualNumberOfDays++;
}
else if(start.getDayOfWeek() == 7){
start.addDays(1);
actualNumberOfDays++;
}
}
}
}
return start;
}
},
Labels:
31 REPLIES 31
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 07:20 AM
That Schedule is the same as everyone has, the OOTB 8-5 weekdays schedule.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 09:39 PM
If screenshot is shared it would be helpful.
Also as mentioned in previous comment, update the durations in seconds as per the Schedule timings.
Thanks