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

Calculating future date by multiplying current date with a number (of days).

Community Beginner ,
Sep 07, 2021 Sep 07, 2021

Hello,

Greatly appreciate any help I can get in writing a formula in Java Script in a form that I created in Adobe DC Pro. I have never done that before. I only know very basics of Adobe, so please make it as simple as possible.

Here is what I need:

I want a field with current date (Field 1), multipied by a number of days (Field 2) and it calculates future date automatically (Field 3).

For example, I want to schedule a follow up in 30, 60, 90 or 180 days from todays date; I fill in today's date in Field 1, then enter number of days that follow up is desired in field 2 and then it automatically calculates the follow up date in Field 3.

Thank you.

TOPICS
How to , JavaScript , PDF forms
1.4K
Translate
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
Engaged ,
Sep 07, 2021 Sep 07, 2021

Hi akhtaraz,

 

Think the following might be of use;

 

if (this.getField("Field1").value!="") event.value=util.printd("dd/mm/yy",new Date(util.scand("dd/mm/yy",this.getField("Field1").value).getTime()+(1000*3600*24*this.getField("Field2").value)));
else event.value=this.getField("Field1").value;

 

Obviously adjust according to your own field names....script goes in the "Custom Calculation" of Field3, set Field2 to Number format (0 d.p.). - Oh and Field 1 & 3 to the date format you want, might not be "dd/mm/yy".

Translate
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
Engaged ,
Sep 07, 2021 Sep 07, 2021

....Oh, and I should add....the only reason I managed to get a working script as per earlier, is thanks to the forum experts on here such as; Try67, Nesa Nurani, Berndt, JR Boulay & Thom Parker and alike (apologies to anyone I've missed out/failed to acknowledge!) - their posts and assistance are invaluable in solving issues, and I know that Try67 has a webpage with a plethora of solutions....well worth a look!.

Translate
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 Beginner ,
Sep 07, 2021 Sep 07, 2021

It is a quality of greatness to remember and acknowledge those who have helped you in the past. I surely want to thank all of  them as their knowledge is now trickling down to me.

Translate
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 Beginner ,
Sep 07, 2021 Sep 07, 2021

Thanks a lot "first-officer" for such a prompt response. 

I plugged in all info just as you advised. Not sure what wrong I am doing. Here is what's happening. I put in todays date in Filed 1 (I nmaed it "Start Date" in format mm/dd/yyyy), then when I put just one digit in Field 2 (I named it "Number of days" in format number), formula calculates this in Filed 3 (I named it "End Date" in format mm/dd/yyyy) to give a date which is addition of that digit in Field 2 to the month in "Start Date". If I add more than one digit in Filed 2, it still changes the month by adding first digit to the month and adding just "One" to the date in Filed 1.  

Here is the example: 

I entered 09/07/2021 in Field 1, then filled 3 or 6 or 9 in Field 2, it calculates 12/07/2021 or 15/07/2021 or 18/07/2021 respectively in Field 3.

If I change digit to 30 or 60, it calculates, it claculates 08/08/2021 or 07/09/2021 or 07/10/2021 respectively in Field 3.

It is also giving the attached error message.

Please assist me in correcting the problem. 

Thanks.

Translate
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
Engaged ,
Sep 07, 2021 Sep 07, 2021

Hi akhtaraz,

 

Have attached an example file for you, hopefully helps? easier to send an example ;-).

 

 

Translate
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 Beginner ,
Sep 07, 2021 Sep 07, 2021

Thanks, can youplease send the fomula you used in this example.

I have revised my "Custom calculations" with the names of the fields as follows. I think, I am doing it wrong.

Here are revised name of the fieldss:

Filed 1: Start Date; Field 2: Number of days; Field 3: End Date

 

Formula I am using in "Custom calculations":

 

if (this.getField("Start Date").value!="") event.value=util.printd("dd/mm/yy",new Date(util.scand("dd/mm/yy",this.getField("Start Date").value).getTime()+(1000*3600*24*this.getField("Number of days").value))); else event.value=this.getField("End Date").value;

Translate
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 Beginner ,
Sep 08, 2021 Sep 08, 2021

Hello "first-officer",

I found the problem and was able to fix it. 

In the formula Date was "dd/mm/yy" whereas I had "mm/dd/yyyy" so I changed the formula to match the format of the field and it worked.

Thank you so much for all your help. Greatly appreciate it.

 

Translate
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
Engaged ,
Sep 08, 2021 Sep 08, 2021
LATEST

Hi akhtaraz,

 

Apologies for not replying sooner - other work committments sadly have precuded an earlier reply, but am glad you mnaged to adjust and get to work for yourself ;-).

 

 

Translate
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