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.

FormCalc time calculation 24 hour format

Avatar

Level 1

Need help with a FormCalc script for time diffrence in 24 hour format on same day.

My table have repeted rows. User enter date, start time, end time and break time for each row

If he starts work midnight he enter 00:00 and if ending midnight he enter 00:00 (display set to "KK:MM" therefore 00:00 = 24:00)

All work great when entering 00:00 to 23:59

But when entering 00:00 (24:00) in end time the diffrence is -24 hours

What line do I need to add so it will work with 00:00 in the WorkTo?

form1.#subform[0].Table1.Row1.WorkTotalWorkTotal::calculate - (FormCalc, client)

var startTime = Time2Num(WorkFrom.formattedValue, "HH:MM")

var finishTime = Time2Num(WorkTo.formattedValue, "KK:MM")

if (WorkFrom==null | WorkFrom=="" |  WorkTo==null | WorkTo=="")

then $=""

else

$=((finishTime) - (startTime)) / 3600000 - WorkBreak

endif

2 Replies

Avatar

Level 10

Since 00:00 and 24:00 are the same, you'll have to add another if expression:

if (not WorkFrom.isNull and not WorkTo.isNull) then

var startTime = Time2Num(WorkFrom.formattedValue, "HH:MM")

var finishTime = Time2Num(WorkTo.formattedValue, "KK:MM")

if (startTime eq finishTime) then

$ = 24

else

$ = (finishTime - startTime) / 3600000

endif

else

$ = ""

endif

Avatar

Level 1

Good day radzmar

Thanks for your reply

If I enter 00:00 to 24:00 the result is 24 hours which is corect

If I enter 01:00 to 24:00 the result is -1 which should be 23 hours (I do understand that is calculate "00:00" - "01:00" = -1)

1407763_pastedImage_1.png

Where im struggling is - if Work To is 24:00/00:00 then the calculation should be "Work to - Frok From" + 24, but dont know how the convert this to FormCalc script

Cheers