Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Calculate Total Business Duration since Created on date to now date

Supriya Sasetti
Tera Contributor

Hi,

I need to calculate Business duration from Idea being Created on to till present day.

Below is the script i used so far:

var start = new GlideDateTime(gr.sys_created_on);

var end = new GlideDateTime(gs.now());

var dc = new DurationCalculator();

dc.setSchedule('sys_id of schedule');

var dur = dc.calcScheduleDuration(start,end);

 

var dur1 = new GlideDuration(dur);

gr.u_total_duration = dur1.getDurationValue();

 

here i am getting only minutes 

1 REPLY 1

Ajay Sharma2
Tera Guru

Hi Supriya,

 

You may try with below code :

var sys_created_on = new GlideDateTime('2024-09-10 00:00:00'); // Replace it with gr.sys_created_on
var current_system_date = new GlideDate();
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae', '8-5 weekdays'); // Replace it with the sys_id of the schedule (Try with GlideRecord and no hardcoding)
 
var duration = schedule.duration(sys_created_on, current_system_date);
gs.info(duration.getDisplayValue());