Avatar

Level 10

Hi,

just a different approach by myself.

To calculate the time difference between two time I use the following script.

It recognises if the date line has been passed (worked from 10.00pm to 07.00 am for example) so you cannot get negative results.

var TimeCount

var OneMinute = 1/60


if (StartTime ne null and EndTime ne null) then

     //if start time is lower than end time.

     if (Time2Num(StartTime.formattedValue, "HH:MM") < Time2Num(EndTime.formattedValue, "HH:MM")) then

          TimeCount = Abs(Time2Num(StartTime.formattedValue, "HH:MM") - Time2Num(EndTime.formattedValue, "HH:MM")) /(60 * 60 * 1000)

     //If start time is higher than end time we passed the date line

     else

          TimeCount = 24 - Abs(Time2Num(EndTime.formattedValue, "HH:MM") - Time2Num(StartTime.formattedValue, "HH:MM")) /(60 * 60 * 1000)

     endif

endif

$ = Round(TimeCount / OneMinute)

To get the number of hours and minutes in the format HH:MM I add a for loop.

var TimeCount

var OneMinute = 1/60


if (StartTime ne null and EndTime ne null) then

     //if start time is lower than end time.

          if (Time2Num(StartTime.formattedValue, "HH:MM") < Time2Num(EndTime.formattedValue, "HH:MM")) then

               TimeCount = Abs(Time2Num(StartTime.formattedValue, "HH:MM") - Time2Num(EndTime.formattedValue, "HH:MM")) /(60 * 60 * 1000)

          //If start time is higher than end time

          else

               TimeCount = 24 - Abs(Time2Num(EndTime.formattedValue, "HH:MM") - Time2Num(StartTime.formattedValue, "HH:MM")) /(60 * 60 * 1000)

          endif


     var Minutes = Round(TimeCount / OneMinute)

     var Hours = 0

     for i = 0 upto 48 step 1 do

          if (Minutes >= 60) then

               Minutes = Minutes - 60

               Hours = i + 1

          endif

     endfor

     $ = Concat(Hours, " hours and ", Minutes, " minutes")

endif

For the total minutes I simply use

Sum(Page.Day[*].ResultMinutes)

And for the total hours and minutes

var TimeCountTotal = Sum(Page.Day[*].ResultMinutes)

var Hours = 0

for i = 0 upto 144 step 1 do

     if (TimeCountTotal >= 60) then

          TimeCountTotal = TimeCountTotal - 60

          Hours = i + 1

     endif

endfor

$ = Concat(Hours, " hours and ", TimeCountTotal, " minutes")

Here's a sample form I made for you, hope this helps

https://acrobat.com/#d=hFcOm4rNgQBO6DzYzrrKwA