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

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

320

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

correct answers 1 Correct answer

Community Expert , 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.

Votes

Translate

Translate
Community Expert ,
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.

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 ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

LATEST

Thank you!!  Works beautifully!

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