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

If/max and ceiling statements in PDF Forms

New Here ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

Hello,

 

I am trying to take a formula I use in Excel and apply it to the PDF invoice version for people to enter manually then they want. 

I have a PDF with forms and the fields I need to calculate are two time fields (HH:MM) and I want them to be subracting so that I can have the duration, but I need that duration in a number format and to 1 =  1 hour, and after that to go up in increments of 0.5. 

In Excel I use the formula:

=IF(C1<=TIME(1,0,0),1,CEILING(C1*24,0.5)) which can also be simplified (I believe, haven't tried) with

=MAX(1,CEILING(C1*24,0.5))

 

can I do the same in PDF Forms so that when a start and end time are entered into two seperate fields, I would end up with an integer in a seperate field?

 

Example:

Start Time Field = 12:30

End Time Field = 14:45

Calculation Field = 2,5

 

Thank you very much for your help!

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms

Views

61

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 ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

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 ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

LATEST

Try this as custom calculation script of 'calculate' field (change "Start Time" and "End Time" to your actual field names):

var startTime = this.getField("Start Time").valueAsString;
var endTime = this.getField("End Time").valueAsString;

if (startTime && endTime) {
 var startParts = startTime.split(":");
 var endParts = endTime.split(":");
 var startMinutes = parseInt(startParts[0]) * 60 + parseInt(startParts[1]);
 var endMinutes = parseInt(endParts[0]) * 60 + parseInt(endParts[1]);
 var diffMinutes = endMinutes - startMinutes;
 var decimalHours = diffMinutes / 60;

 if (decimalHours <= 1) {
  event.value = 1;} 
 else {
  event.value = Math.ceil(decimalHours * 2) / 2;}} 
else {
 event.value = "";}

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