Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

FormCalc - How to calculate difference between two datetime fields in HH:MM ?

Avatar

Former Community Member

Hello!

I'm building a timesheet form in which I need to calculate the difference between start and end times and present the result.

I'm trying to do this with FormCalc but if it is easier with JS it's ok too.

So this is what I did on the total field, using the calculate event on a NUMERIC field called decimalValue:

     elapsed = Time2Num(endTime.formattedValue, "HH:MM") - Time2Num(startTime.formattedValue, "HH:MM")

 

And then I tried to convert into a time field:

     total = decimalValue.rawValue;

     $.formattedValue = Num2Time(total, "HH:MM")

Well, it doesn't work, it gives me crazy results in the datetime (total) field. If I type 09:00 and 09:30, the end result is... 22:30. Huh?

 

Please, could someone help me understand how this thing works? 

 

Thank you very much for any hints!

 

Marcos

1 Accepted Solution

Avatar

Correct answer by
Level 10
2 Replies

Avatar

Correct answer by
Level 10

Avatar

Former Community Member

Thank you NIall!

Always coming to the rescue! Thanks!!

Marcos