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.
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.