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

Simple Time Calulation for fillable pdf

New Here ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

I have a fillable pdf set up for technicians daily activities. Part of this is daily time. I have start time hours, start time minutes, Start time AMPM, break, end time hours, end time minutes, end time AMPM. I used Thom's script calculates time worked correctly but when the boxes are empty, the total worked displays 24.

 

//Get Time Values

var StartTimeHour = this.getField("STH1").value;

var StartTimeMin = this.getField("STM1").value;

var StartTimeAP = this.getField("STAP1").value;

var EndTimeHour = this.getField("ETH1").value;

var EndTimeMin = this.getField("ETM1").value;

var EndTimeAP = this.getField("ETAP1").value;

var BreakTime = this.getField("Break1").value;

//Combine Time Values

var StartTime = (StartTimeHour + StartTimeMin + StartTimeAP);

var EndTime = (EndTimeHour + EndTimeMin + EndTimeAP);

//Calculate Time

var TimeWorked = ((EndTime - StartTime) - BreakTime);

//Test for Midnight Crossover

if(TimeWorked < 0) {// Shift 24 hours

TimeWorked += 24;

} else if(TimeWorked === 0) {//Shift 24 hours for same times

TimeWorked += 24;

}

//Print Results

event.value = TimeWorked;

 

The Option values for hours are set up 1=1-11=1 12=0. My minutes are 00, 15, 30, 45. AM PM is 0 and 12

I do have blanks in the options so the boxes are empty when not in use

 

 

TOPICS
Edit and convert PDFs , PDF forms

Views

478

Translate

Translate

Report

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

Can the times be more than 24 hours apart? If so, you have to include the full date, as well.

Otherwise the script can't know if 9:00-10:00 means 1 hour, 25 hours, 49 hours, etc.

Votes

Translate

Translate

Report

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

We run 2 shifts. ^:00 AM to 4:00 PM and 7:30 PM to 7:00 AM

Votes

Translate

Translate

Report

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

6:00 AM to 4:00 PM

Votes

Translate

Translate

Report

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

LATEST

Then you don't need this condition at all:

 

else if(TimeWorked === 0) {//Shift 24 hours for same times

TimeWorked += 24;

}

Votes

Translate

Translate

Report

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