Time calculations past midnight

Avatar

Avatar

Gene--O

Avatar

Gene--O

Gene--O

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

Avatar

Avatar

Gene--O

Avatar

Gene--O

Gene--O

18-11-2011

Radzmar,

I’m sorry to bother you again, BUT, I have run into a problem. In certain instances, the calculation does not handle crossing midnight well at all. I have attached a copy of the form so you can see the results.

Please note on Thursday the 3rd, and Friday the 4th, I am getting a negative hour value return.

Will you please help me again!

Thanks!

Lt. Gene Schrieber

Alabama Alcoholic Beverage Control Board

Enforcement District 1

P.O. Box 1755

Florence, Alabama 35631

(256) 764-2435

(256) 766-1793 Fax

www.abc.alabama.gov

"It's not about where you've been, it's where you are going that matters"