Skip to main content
Participating Frequently
May 26, 2025
Answered

Calculate break times - timesheet

  • May 26, 2025
  • 1 reply
  • 359 views

Hi, I have a script to calculate the hours worked between two times - will include it below. I would like to automatically deduct breaks from the result so if the 'Hours' result is >6 but <12 then i want it to deduct 0.5hrs and if the resultis >=12 then i want it to deduct 1 hr, could anyone please help (hours in screenshot aren't relevant as only 3 hrs but just to show the layout of the form)?

 

 

 

if ((this.getField("End TimeRow1").value.length == 0) || (this.getField("Start TimeRow1").value.length == 0)) {

event.value = " 0 Hours 0 Minutes";

}

else{

var timefinished = this.getField("End TimeRow1").value;

var timestarted = this.getField("Start TimeRow1").value;

var datetimefinished = new Date('1970/01/01' + " " + timefinished);

var datetimestarted = new Date('1970/01/01' + " " + timestarted);

if(datetimefinished<datetimestarted)
{
var date=new Date(datetimefinished)
date.setDate(date.getDate()+1);
datetimefinished=date;
}

var difflnMilliSeconds = Math.abs(datetimefinished - datetimestarted)/1000;

var hours = Math.floor(difflnMilliSeconds / 3600) % 24;

difflnMilliSeconds -= hours *3600;

var minutes = Math.floor(difflnMilliSeconds / 60) % 60;

difflnMilliSeconds -= minutes * 60;

event.value = hours + (minutes/60) ;

}

Correct answer PDF Automation Station

Replace

event.value = hours + (minutes/60) ;

}

WITH

var rslt=hours + (minutes/60);
if(rslt>6 && rslt<12)
{event.value=rslt-0.5}
else if
{rslt>=12)
{event.value=rslt-1;}
else
{event.value=rslt}
}

1 reply

PDF Automation Station
Community Expert
Community Expert
May 26, 2025

Replace

event.value = hours + (minutes/60) ;

}

WITH

var rslt=hours + (minutes/60);
if(rslt>6 && rslt<12)
{event.value=rslt-0.5}
else if
{rslt>=12)
{event.value=rslt-1;}
else
{event.value=rslt}
}
Participating Frequently
May 26, 2025

Thank you :)!