How to find time difference between Date-Times and set to Time field of Creator

How to find time difference between Date-Times and set to Time field of Creator

STEP 1. FIND TIME GAP using `timeBetween`

  1. startTime = zoho.currenttime.subHour(2).subMinutes(24).subSeconds(4);
  2. endTime = zoho.currenttime;
  3. timeGap = startTime.timeBetween(endTime);

STEP 2: Structure Time String for Time Field

There's an issue with the time_gap function. It only returns a value when there's a difference between the compared times. If there's no difference, the function returns nothing.

To address this, we can loop through a range of three values (0 to 2) and replace any empty responses with "00".
  1. timeList = timeGap.toList(":");
  2. finalTime = "";
  3. loopArr = [0,1,2];
  4. for each i in loopArr {
  5. scaleTime = (if(timeList.size() > i,timeList.get(i), "00").toString().leftPad(2)).replaceAll(" ", "0");
  6. finalTime = finalTime +":"+ scaleTime;
  7. }
  8. info finalTime.removeFirstOccurence(":");
You can use finalTime variable to assign in Time field.

Coding is fun :) Have a great day!