Skip to main content
Participant
October 3, 2022
Answered

Calculating Regular Hours and Overtime Hours

  • October 3, 2022
  • 2 replies
  • 4675 views

I am creating a timesheet that requires taking the total amount of hours worked and slitting them up between regular hours worked and overtime hours worked. 

 

Three columns:

(TotalHours) The first column I have the total amount of hours worked in the week. The caluation to add up the hours worked each day is easy and works. 

(RegHours) The second colum would be the total of regular hours worked, which would equal 40 hours or less. 

(OTHours) The thrid column would be the total hours worked over 40 hours. 

 

Hour would I write the code for the Regular and Overtime hour calculations? 

This topic has been closed for replies.
Correct answer Nesa Nurani

For regular hours use this:
var h1 = Number(this.getField("TotalHours1").value);
if(h1 > 40)event.value = 40;
else
event.value = h1;

For overtime hours use this:
var h2 = Number(this.getField("TotalHours1").value);
var h = 0;
if(h2 > 40)h = h2-40;
if(h2 > 40)
event.value = h;
else
event.value = "";

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
October 4, 2022

For regular hours use this:
var h1 = Number(this.getField("TotalHours1").value);
if(h1 > 40)event.value = 40;
else
event.value = h1;

For overtime hours use this:
var h2 = Number(this.getField("TotalHours1").value);
var h = 0;
if(h2 > 40)h = h2-40;
if(h2 > 40)
event.value = h;
else
event.value = "";

Participant
October 4, 2022

Thank you very much! Worked like a charm. All the other post I review weren't quite the right answer for what I was trying to accomplish. 

Participant
April 12, 2023

Totally. No one else had it quite right, thank you!

try67
Community Expert
Community Expert
October 4, 2022

This issue was discussed here many (many) times in the past. Did you try searching the forum for past discussions?