Print Page | Close Window

Custom Script to Calculate Date to Percentage

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 20 May 2019 at 4:20am
Software Version: Web Wiz Forums 11.10 -

Topic: Custom Script to Calculate Date to Percentage
Posted By: Charlooney
Subject: Custom Script to Calculate Date to Percentage
Date Posted: 21 Feb 2017 at 6:24pm
Hello all,

I have been beating my head against a wall trying to sort the very last formula in the form I am designing. I'm under a bit of a time crunch, so any help is very very much appreciated.

My form is being used to calculate a percent payable amount in relation to hours of the day. For example:

Start Time = 12:00, Finish Time = 14:00, thus 8% of the day is the calculation result and the amount payable.

However, for events that run multiple days it would look something like this:

Line 1 - Start Time = 12:00, Finish Time = --, 50% payable
Line 2 - Start Time = --, Finish Time = 12:00, 50% payable

I have the simple notations for the calculation above, not a problem, but cannot get these both to work together (to ensure that the formula is present if anyone should have a start and finish time in the same day).

In addition, if neither the Start Time, nor the Finish Time is present, I need the default value to be 100% (I've set this in the Options Tab, but it disappears as soon as there is a calculation present).

I've been playing with an if, else in the script, but am wondering if the default to 100% needs to be a formatting script instead? If so, I would need to ensure it is formatted as a percent, but calculates as a number.

I feel like this may be an easy solution that I am over thinking. Any help is greatly appreciated; Many thanks!

Warm Regards,

Posted By: Charlooney
Date Posted: 23 Feb 2017 at 5:35am
Hello all,

An update to say that I have sorted the 100% issue with a handy formatting script, so no worries.

I am at war with the last bit though ...

I no longer need these to work together -- only a calculation IF either Start Time or Finish Time is input.

Due to the formulas required to get the overall percentage, this cannot be done via a simplified notation, it must be a custom script.

My starting point formulas, to get the correct percentage for the Start Time (the amount remaining in the day) and FinishTime (the amount of the day that has elapsed):


I believe I need an IF statement to get either one to show, so IF Start Time is greater than 0, then the final value is (StartTimeRow1/24-1). Then an else if, very similar for the Finish Time.

However, every script I write results in zero calculation. Head. Desk.

Many thanks for anyone who can offer assistance, my brain is fried!!

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -