Calculate Business Days
- 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;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 08:16 AM
Hi,
You can check the below thread to calculate business days using a schedule.
How to calculate 5 working days using scehdule and display the future date
Regards,
Gunjan
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 08:24 AM
Thank you, i'm trying this out now...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 08:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 09:11 AM