var startDateTime = new GlideDateTime("2025-03-01 09:00:00"); //enter employee start date here
// Instantiate a new GlideDateTime object which has the current date and time
var endDateTime = new GlideDateTime();
var dur = new DurationCalculator();
// Set 9-5 weekday schedule. This is the schedule used below with 8 business hours
dur.setSchedule('a859c8c3e4e98500ea445bbba64fd9f8'); //enter your desired schedule sys_id
dur.calcScheduleDuration(startDateTime, endDateTime);
var secs = dur.getSeconds(); //Business time in secs
var totalSecs = dur.getTotalSeconds(); //Total time in secs
gs.print("***SCHEDULE DURATION: Business Days=" + Math.round(secs/(3600*8)) + " TOTAL Days=" + Math.round(totalSecs/(3600*24)) );
Difference between two dates in business duration using ServiceNow schedule
Working Code Asked question March 6, 2025
Sorry, you do not have permission to read comments.