Calculate Working Days Using Schedule
Import
·
Feb 11, 2022
·
article
Run the below function in the background script to calculate total Working days using Schedule.
function getDiff(date1, date2) {
/*
@param1- Date value
@parm2- Date value
@return- woking days value in second
*/
var updatedDate = new GlideDateTime(date1); //old date
var currDate = new GlideDateTime(date2); //latest date
var schedID = 'Pass the sys_id'; //Parent sys_id of the schedule
var durationCalculator = new DurationCalculator();
durationCalculator.setSchedule(schedID);
var diff;
if (currDate > updatedDate) {
diff = durationCalculator.calcScheduleDuration(updatedDate, currDate);
} else {
diff = durationCalculator.calcScheduleDuration(currDate, updatedDate);
}
if (diff != '' || diff != 0 || diff != '0' || diff != undefined || diff != null)
return diff; //diff / 60 / 60 / 24 - To convert into days
return 0;
}
gs.info(getDiff('2022-02-11 15:23:25','2022-02-18 15:23:25'));
gs.info(getDiff('2022-02-11','2022-02-18'));
Please Mark it helpful if it helps you.
View original source
https://www.servicenow.com/community/itsm-articles/calculate-working-days-using-schedule/ta-p/2300478