Level 1

0% to

Level 2

Tip /

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

View all

## Calculating times 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

29-11-2011

Hello All,

I am working on a timesheet for employees. It has 4 time fields (amIN, amOUT, pmIN, pmOUT) to allow for a lunch break. I have a script that calculates well for normal business hours. BUT, if the work shift goes past midnight, then it does not calculate correctly.

Here is what I have in FormCalc in a calculate event:

var fullTime = 0
var breakTime = 0

if (pmIN ne null and pmOUT ne null) then
if (Time2Num(amIN.formattedValue, "HH:MM") < Time2Num(pmOUT.formattedValue, "HH:MM")) then
fullTime = Abs(Time2Num(amIN.formattedValue, "HH:MM") - Time2Num(pmOUT.formattedValue, "HH:MM")) /(60 * 60 * 1000)
else
fullTime = 24 - Abs(Time2Num(pmOUT.formattedValue, "HH:MM") - Time2Num(amIN.formattedValue, "HH:MM")) /(60 * 60 * 1000)
endif

breakTime = Abs(Time2Num(pmIN.formattedValue, "HH:MM") - Time2Num(amOUT.formattedValue, "HH:MM")) /(60 * 60 * 1000)
\$ = fullTime - breakTime
else

fullTime = Abs(Time2Num(amIN.formattedValue, "HH:MM") - Time2Num(amOUT.formattedValue, "HH:MM")) /(60 * 60 * 1000)
\$ = fullTime

if (amIN == null) then \$=null else \$=(fullTime - breakTime)
endif

endif

thanks

Gene-O

View Entire Topic

sonyapatton123
Level 1

Likes

0 likes

Total Posts

4 posts

0 solutions
View profile

sonyapatton123
Level 1

Likes

0 likes

Total Posts

4 posts