Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## Time calculations past midnight

Gene--O
Level 2

Likes

3 likes

Total Posts

76 posts

0 solutions
View profile

Gene--O
Level 2

Likes

3 likes

Total Posts

76 posts

0 solutions
View profile
Gene--O
Level 2

14-11-2011

Hello All,

I have created a timesheet that calculates times for me. BUT I have a problem when the shift ends at midnight, or goes past midnight.

I have 4 time fields: amIN, amOUT, pmIN, pmOUT, and then a Total Hours Field.

Everything works fine up until midnight.

I have the follwing script in FormCalc as a calculate event of the Total Hours Field (taken from an example previously sent to me:

var amIn = Time2Num(amIN, "HH:MM")

var amOut = Time2Num (amOUT, "HH:MM")

var pmIn = Time2Num (pmIN, "HH:MM")

var pmOut = Time2Num (pmOUT, "HH:MM")

var vTotal = 0

if (amIn <> "" and amOut <> "") then

if (amOut lt amIn) then

xfa.host.messageBox("The morning times are inccorect", "oops", 0,0)

else

vTotal = (amOut - amIn) / (60 * 60 * 1000)

endif

if (pmIn <> "" and pmOut <> "") then

if (pmOut lt pmIn) then

xfa.host.messageBox("The afternoontimes are inccorect", "oops", 0,0)

else

vTotal = vTotal + (pmOut - pmIn) / (60 * 60 * 1000)

endif

\$ = vTotal

This works great, but if you go up until midnight, say a 3:00pm - 12:00am shift, then you get the error. I need this to calculate including, or even past midnight, ex. a 5:00pm - 2:00am shift.

thanks for any and all help!!

Gene-O

View Entire Topic

CJ54235
Level 1

Likes

0 likes

Total Posts

10 posts

1 solution
View profile

CJ54235
Level 1

Likes

0 likes

Total Posts

10 posts

1 solution
View profile
CJ54235
Level 1

03-12-2012