How to calculate no of business days between two date?

Rahul Chaudhary
Tera Contributor

Hi Team,

could you please help to find number of business days between two dates in ServiceNow?

9件の返信9

Open that record and check if you have schedule entries like below

HarishKM_0-1697772590659.png

 

Regards
Harish

Yes, i checked both 8A.M to 5P.M and 9A.M to 7P.M.

 

RahulChaudhary_0-1697772907251.png

 

 

Can you run the below script via background script and check

var startDate = new GlideDateTime('2023-10-11 09:36:07');
var endDate = new GlideDateTime('2023-10-18 09:36:07');
var schedule = new GlideSchedule();
 
schedule.load('38fa64edc0a8016400f4a5724b0434b8'); // sys_id of your Schedule you created for Business Days
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule
Regards
Harish

Output is 7 00:00:00. if using same schedule and code. could you please guide what wrong going with my schedule?

I would suggest compare with OOB schedule and find the difference

Regards
Harish