Difference between two times

Can anyone help with how to get the difference between two times.

Example: Time in: 6:30

Time out: 18:21

The difference should be 11.51 i.e 11 hours, 51 minutes.

Hi,

Two options -

  1. Global > timeConsumed

  2. DateTimeUtil > getDifference

Hope this helps.

hi,

In a job its return difference only in seconds.

you can get 11.50 once you saved in table;

Public static real TotalHours()
{

real Hours;
TimeofDay timein,timeout;

Hours = _timeout- _timein;

if(Hours > 0)
return Hours; // else return hours/3600 – to return 11.50
else
return 86400 + Hours; // else return hours/3600 – to return 11.50

}

Hope its help you

Hi,

you can use timeconsumed() – but you have to given input in seconds()

Hello Mr Harish Mohanbabu,

Can you please tell in detail how to use these two options -

  1. Global > timeConsumed

  2. DateTimeUtil > getDifference

Thanks & Regards

Pranav Gupta

Hope this helps -

static void HM_TimeDiff(Args _args)
{
    FromTime        fromTime;
    ToTime          toTime;
 
    FromDateTime    fromdt;
    ToDateTime      todt;
    ;
 
    fromTime    = timeNow();
    toTime      = timeNow() + 500;
 
    //Timeconsumed()
    info(strFmt('Time consumed %1', timeConsumed(fromTime, toTime)));
 
    fromdt      = DateTimeUtil::newDateTime(systemDateGet(),timeNow());
    todt        = DateTimeUtil::newDateTime(systemDateGet(),timeNow() + 500);            
 
    //DateTimeUtil::getDifference
    info(strFmt('Get difference %1', time2StrHMS(int642int(DateTimeUtil::getDifference(todt, fromdt)))));
}    

In addition to above, the following code can also be used for time difference -

info(strFmt('Time difference %1', time2StrHMS(toTime - fromTime)));

Thank you Mr. Harish Mohanbabu.