- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 12:54 AM
I want to get number of working days between start date and end date in a business rule.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 08:38 AM
add +1 to business_days. That should solve the issue
Use the below logic to add 1
var dc = new DurationCalculator();
dc.setSchedule('eb65c2250fc76340e1f30dbce1050ee2', 'Los Angeles'); // Schedule sys_id and system time zone
var dur = dc.calcScheduleDuration(start, end);
var business_days = dur/(60*60*9); // Update the t
var gdt = new GlideDateTime(end);
var day_of_month = gdt.getDayOfWeekUTC();
if(day_of_month < 6)
business_days += 1;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 08:14 AM
Check if the schedule that you are using is excluding US holidays ?
Also
calcScheduleDuration
returns difference between days
for example
var start = new GlideDateTime('2019-02-04');
var end = new GlideDateTime('2019-02-05');
this will return 1 day not as two days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 08:27 AM
No I'm using 8-5 weekdays schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 07:40 AM
var start = new GlideDateTime('2019-02-01');
var end = new GlideDateTime('2019-02-28');
var dc = new DurationCalculator();
dc.setSchedule('090eecae0a0a0b260077e1dfa71da828', 'Los Angeles'); // Schedule sys_id and system time zone
var dur = dc.calcScheduleDuration(start, end);
var business_days = dur/(60*60*9); // Update the total hours of a day based on shedule
gs.info(business_days);
for the above script I'm getting 18 as business days, whereas for feb month its 20
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 07:48 AM
for even numbered months I'm not getting the proper result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2019 07:53 AM
Check that your schedule is floating timezone or have the same as you parse
And log out your gdt to see what time you get.
Glidedatetime used utc and not los angeles so make sure that all times and scheduke uses the same timezone