Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

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

Learn More

View all

Sign in to view all badges

Time calculations past midnight

Avatar

Avatar
Validate 10
Level 2
Gene--O
Level 2

Likes

3 likes

Total Posts

76 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
Gene--O
Level 2

Likes

3 likes

Total Posts

76 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
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

Avatar

Avatar
Affirm 1
Level 1
CJ54235
Level 1

Likes

0 likes

Total Posts

10 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile

Avatar
Affirm 1
Level 1
CJ54235
Level 1

Likes

0 likes

Total Posts

10 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile
CJ54235
Level 1

03-12-2012

Hi Radzmar!

I am a newbie to writting FormCalc. I have tried to tweak your sample to fit my needs with no luck.

I have 6 fields for each weekday - in & out times for morning, afternoon, and overtime. I haven't even attempted to look at how overtime is calculated. Right now I am just trying to get the hours calculated for morning and afternoon minus the lunch break. I have attached a link to my feeble attempt in the hopes you could look at it.

http://www.whitetailsunlimited.com/i/p/TimeSheet20121203.pdf

Thanks much in advance!

CJ