Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Time calculations

Avatar

Former Community Member
We are trying to create a function using FormCalc to calculate the number of hours elapsed between two time values in HH:MM format.



Any ideas?
2 Replies

Avatar

Level 5
I remember solving similar problem by separating HH and MM form the values and adding individually. And then check the value of MM and if it is more than 59 do the following (totalHH + 1) and (totalMM - 60). Finally use TotalTime.rawValue = Concat(totalHH, ":", totalMM) to get the desired value.



Good luck,

SekharN

Avatar

Former Community Member
Thanks for this. My colleague seems to have cracked it.



var t = (Time2Num(hoursto.formattedValue, "HH:MM") - Time2Num (hoursfrom.formattedValue, "HH:MM") + 1 - (60*60*1000))

totalhour.formattedValue = Num2Time(t, "HH:MM")



It kept falling over because we used rawValue instead of formattedValue.



He then moved the script to calculate on exit from the Hours To field rather than trying to do the calculation in the total hours field.