Notifications

67 views

Description

This article is providing the way to calculate the duration of days by using Scheduler function in Script.

With Scheduler, it is easy to calculate the duration with some option, like exclude week-end or holiday.

Instructions

You can calculate the duration of 2 days in the next step:

  1. Open Scheduler ("System Scheduler -> Schedules -> Schedules")
  2. Open the schedule you want to use. In this example, using "8-5 weekdays" to calculate exclude weekend.
  3. Check the option : All Day. If this is not checked, the calculation is consider only business hour set in the scheduler.
  4. Prepare the script. Please refer the below sample.

If you need to calculate exclude holiday, please use the schedule: "8-5 weekdays excluding holidays"

 

Sample

var startDate = new GlideDateTime('2020-4-17 00:00:00');
var endDate = new GlideDateTime('2020-4-21 00:00:00');
var schedule = new GlideSchedule();

schedule.load('08fcd0830a0a0b2600079f56b1adb9ae'); // loads "8-5 weekdays" schedule. ('08fcd0830a0a0b2600079f56b1adb9ae' is sysid of the schedule.)
var duration = schedule.duration(startDate, endDate);
gs.print(duration.getDurationValue()); // gets the elapsed time in schedule

 

Result of the code

2 00:00:00

Article Information

Last Updated:2020-05-13 18:05:44
Published:2020-04-28