Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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
Kilo Sage

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());