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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Calculating Time

Avatar

Level 4

Good Afternoon All,

I am creating a timesheet that covers a two week period. I have a table set up with the following fields:

TimeIn1, TimeOut1, TimeIn2, TimeOut2, Total Hours, OT Hours

The user will input their times for the morning (TimeIn1 and TimeOut1) and then the afternoon (TimeIn2 and TimOut2) for each day. I need the Timesheet to calculate how many hours were worked in that day. I would like it to round to the nearest quarter hour. At the end of the week, I need the form to add how many hours were worked for the week, and place any hours over 40 into the "OT Hours" field.

I am VERY limited in FormCalc and Javascript, so if you reply, PLEASE try to explain to me what you have done!

Thank you!!!!

Gene-O

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Gene-O,

Here is a sample: https://acrobat.com/#d=kCPIgVkd09qrx6h-WRXxbQ

It is all FormCalc and the script is in three locations. The daily hours field has a basic check to see that the fields are not null and that the In time is before the Out time. The total normal hours does a basis addition of the daily totals and then checks if this is greater than 40hrs. If it is, then it limits the normal hours to 40hrs and spills the rest into overtime hours. The last script is in the total hours field that basically adds the normal and total hours together.

The only function used is Time2Num, which converts the inputted time into a number. This allows you subtract times. The time is in milliseconds so dividing by (60 * 60 * 1000), converts it back to hours.

The time function is tricky, if the user does not input a time correctly, the function will return "0". I have tried to capture this in a validation script.

Hope that gives a direction.

Niall

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

Hi Gene-O,

Here is a sample: https://acrobat.com/#d=kCPIgVkd09qrx6h-WRXxbQ

It is all FormCalc and the script is in three locations. The daily hours field has a basic check to see that the fields are not null and that the In time is before the Out time. The total normal hours does a basis addition of the daily totals and then checks if this is greater than 40hrs. If it is, then it limits the normal hours to 40hrs and spills the rest into overtime hours. The last script is in the total hours field that basically adds the normal and total hours together.

The only function used is Time2Num, which converts the inputted time into a number. This allows you subtract times. The time is in milliseconds so dividing by (60 * 60 * 1000), converts it back to hours.

The time function is tricky, if the user does not input a time correctly, the function will return "0". I have tried to capture this in a validation script.

Hope that gives a direction.

Niall