Duration into hours

Deepak92
Tera Contributor

Hi Team,

i am trying to get Aggergate of business duration but not getting expected result , i want it be in hours

var gr = new GlideAggregate("task_sla");
    gr.addAggregate('SUM', 'business_duration');
    gr.addQuery('task.number', caseID);
    gr.addQuery('sla.name', 'MCOE On Hold Time calculation');
    gr.setGroup(false);
    gr.query();
    //var sum=0;
    while(gr.next()) {

        var sum=gr.getAggregate('SUM','business_duration');
        gs.info("SUMTIME" + sum);
        var dur= new GlideDateTime(getValue('sum'));
        var dursec=dur.getNumericValue()/1000;
        gs.info("DURSEC"+dursec);
    }

OUTPUT:

SUMTIME which i am getting is 1 19:17:24  which is submission below( Doubtful)

Business duration =1 day 19 hour 16 min

Business duration =39 sec

Any help would be highly appreciated

Thanks in Advance

Stay Safe

1 REPLY 1

Periyasamy P
Tera Guru

Yes, you are right by default the duration format is "d HH:mm:ss" where "d" is number of days.

From duration, 

1. Get day part using getDayPart() and convert to hours (day*24)

2. Get hour part using  getByFormat('HH')

3. Then add both values

 

Note: If you want more accurate values, then get mins & secs. Convert and add it

getByFormat('mm')

getByFormat('ss')