How to calculate no of business days between two date?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
10-19-2023 07:44 AM
Hi Team,
could you please help to find number of business days between two dates in ServiceNow?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
10-19-2023 08:11 AM
you can use Schedule and handle it
I am also sharing a script
var diff;
var startDate = new GlideDateTime('startDate');
var endDate = new GlideDateTime('endDate');
var sched = new GlideSchedule('38fa64edc0a8016400f4a5724b0434b8'); // sysId of the schedule
diff = sched.duration(startDate,endDate).getDurationValue();
gs.addInfoMessage(diff);
Also check the docs
Using DurationCalculator to calculate a due date
DurationCalculator calcScheduleDuration Mystery
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
10-19-2023 07:54 PM
Hi Ankur,
thankyou for sharing this code.
i am using your code which you provide in answer with replace by my schedule. but i am getting like that in below
00:00:00
could you please guide me what i am wrong in this code?
var diff;
var startDate = new GlideDateTime('2023-10-11 09:36:07');
var endDate = new GlideDateTime('2023-10-18 09:36:07');
var sched = new GlideSchedule('602c74208706b9504bf9a6890cbb35aa'); // sysId of the my schedule
diff = sched.duration(startDate,endDate).getDurationValue();
gs.info("new code===="+diff);

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
10-19-2023 08:25 PM
Hi @Rahul Chaudhary Can you check in cmn_schedule table whether your schedule sysid is valid?
Harish
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
10-19-2023 08:28 PM
Yes Harish, It is valid please refer screenshot of that.