FormCalc time calculation 24 hour format

Avatar

Avatar

Sunaj76

Avatar

Sunaj76

Sunaj76

30-01-2018

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

31-01-2018

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

Avatar

Sunaj76

Avatar

Sunaj76

Sunaj76

31-01-2018

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