How to find time difference between Date-Times and set to Time field of Creator
- startTime = zoho.currenttime.subHour(2).subMinutes(24).subSeconds(4);
- endTime = zoho.currenttime;
- 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".
- timeList = timeGap.toList(":");
- finalTime = "";
- loopArr = [0,1,2];
- for each i in loopArr {
- scaleTime = (if(timeList.size() > i,timeList.get(i), "00").toString().leftPad(2)).replaceAll(" ", "0");
- finalTime = finalTime +":"+ scaleTime;
- }
- info finalTime.removeFirstOccurence(":");
You can use finalTime variable to assign in Time field.
Coding is fun :) Have a great day!