## Calculating times past midnight

Gene--O

Total Posts

76

Likes

3

0

Gene--O

Total Posts

76

Likes

3

0
Gene--O

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

Gene--O

Total Posts

76

Likes

3

0

Gene--O

Total Posts

76

Likes

3

0
Gene--O

06-12-2011

I apologize if I didn't make myself clear! I am just not familiar enough with scripting to know where to insert your script to make it work.

Here is the latest script I have from you. WIll you please insert the addition to make it calculate amIN and amOUT if they are the only two entries?

var fullTime = 0
var breakTime = 0

if (amIN ne null and pmOUT ne null) then
if (Time2Num(amIN.formattedValue, "HH:MM") lt 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
if (amOUT ne null and pmIN ne null) then
if (Time2Num(amOUT.formattedValue, "HH:MM") lt Time2Num(pmIN.formattedValue, "HH:MM")) then
breakTime = Abs(Time2Num(pmIN.formattedValue, "HH:MM") - Time2Num(amOUT.formattedValue, "HH:MM")) /(60 * 60 * 1000)
else
breakTime = 24 - Abs(Time2Num(pmIN.formattedValue, "HH:MM") - Time2Num(amOUT.formattedValue, "HH:MM")) / (60 * 60 * 1000)
endif
endif

\$ = fullTime - breakTime
else
\$ = fullTime
endif

THANK YOU SO MUCH!

Gene-O