## Adobe Support Community

• Calculating Percentage of Time Elapsed

# Calculating Percentage of Time Elapsed

New Here ,
May 18, 2022 May 18, 2022

Copy link to clipboard

Copied

I have four fields on a form:

"StartDate", "EndDate", "EvalDate", (all formatted as: "yyyy mmm dd") and also "PercElapsed" (formatted as a percentage with one decimal place).  The time difference between "EndDate" and "StartDate" is the total period, or duration, of an event.  "EvalDate" is a date between the Start and End dates.  "PerElapsed" returns the value representing the time elapsed on the day of "EvalDate" since the day of "StartDate" (as a percent of the total period).  The "EndDate" field is a future date automatically calculated depending upon the entry in "StartDate" and a multiplier (representing months) selected from a Drop Down (i.e.: if "StartDate" is today and multiplier selected  is "12" then "EndDate" returns a future date exactly 12 months from today - and works very well!.)  The "EndDate" and "PerElapsed" fields have been set as Read-Only.

My dilemma:  writing the code to correctly calculate this percentage:  ("EvalDate"-"StartDate")/("EndDate"-"StartDate")Seems easy enough, but this has busted my chops.....

THANK YOU kindly for all assistance!!

TOPICS
How to , JavaScript , PDF forms

Views

48

Likes

Report

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

## 1 Correct answer

Adobe Community Professional , May 19, 2022 May 19, 2022

You need to convert the values of all the fields to Date objects, using the util.scand method.

Then get the pure numeric values of all of these Dates by accessing their getTime method.

Then perform your calculations and write back the result to the event.value property of the calculated field.

Likes

2 Replies 2
Adobe Community Professional ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

You need to convert the values of all the fields to Date objects, using the util.scand method.

Then get the pure numeric values of all of these Dates by accessing their getTime method.

Then perform your calculations and write back the result to the event.value property of the calculated field.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

LATEST

Thank you!!  Works beautifully!

Likes

Report

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