- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:05 AM
Hi,
How can we calculate business days between two dates i.e. one date value selected in Start Date Field and the other date would be the current Date(Today Date). I have tried the below code but it does not gives me the correct business days value:
gs.info(gs.now());
var date1 = '10/06/2020';
var dc = new DurationCalculator();
dc.setSchedule('Sys Id of the Schedule');
var dur = dc.calcScheduleDuration(date1,gs.now())/3600;
gs.info('Duration is' + dur);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 04:39 AM
Add date in correct format
var date1 = '2020-06-10';
var end = new GlideDateTime(date1);
And try again ...
Mark my ANSWER as CORRECT and HELPFUL if it helps...
Refrence:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:13 AM
Hi,
please refer below links and they will help you:
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 04:21 AM
Hi,
var gdt1 = GlideDateTime('2015-07-24 18:58:00');
var gdt2 = GlideDateTime('2015-07-24 19:01:00');
var duration1 = gs.dateDiff(gdt1, gdt2, false);
Thanks
Santosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 05:44 AM
Hi,
Please try this
Please mark correct or helpful if this helps you.
Thanks
Swapnil