Calculating times past midnight

Avatar

Avatar

Gene--O

Avatar

Gene--O

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

Anybody please help me?

thanks

Gene-O

View Entire Topic

Avatar

Avatar

Gene--O

Avatar

Gene--O

Gene--O

13-12-2011

You are AWESOME!

Thank you so much for your patience and working this out for me!!!