Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculate break times - timesheet

New Here ,
May 26, 2025 May 26, 2025

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)?

 

Carly35100614pxwk_0-1748262009991.png

 

 

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) ;

}

TOPICS
JavaScript , PDF forms
133
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
May 26, 2025 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}
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2025 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}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 26, 2025 May 26, 2025
LATEST

Thank you :)!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines