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.
You can calculate the duration of 2 days in the next step:
If you need to calculate exclude holiday, please use the schedule: "8-5 weekdays excluding holidays"
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