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

add 30 days from the date stamp

Community Beginner ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hello,

can you please help me? I have a form which I send to customers. The first field the will do is select the date they are working on the form... (I still have to figure out how to name the tab so the customer can see the tab name as date), anyways, what I need to happen next is to have my last tab on the bottom auto add 30 days from the date selected by the customer on top.

Example

Customer opens the PDF, and selects the date as 1 may 2018, base of that the form will automatically calculate and add the 30 days as 31 May 2018

This investigation must be completed no later than 31 May 2018. (The 31 May 2018 is auto completed and can not be changed, it will basically inform the customer that that is his/her due date).

Can you please help?

Thank you

HanzCzech

TOPICS
PDF forms

Views

7.4K

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 08, 2018 May 08, 2018

You placed the code in the wrong location. It needs to go under the Calculate tab, in the third option ("Custom calculation script").

Also, if your date format is actually "mm/dd/yyyy" (and not "dd/mm/yyyy", which is what I used) then you need to change that in the code, too.

Votes

Translate

Translate
Community Expert ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Let's say the fields are called Date1 and Date2 and that the format is "dd/mm/yyyy".

Use this code as the custom calculation script of Date2:

var s1 = this.getField("Date1").valueAsString;

if (s1=="") event.value = "";

else {

    var d1 = util.scand("dd/mm/yyyy", s1);

    d1.setDate(d1.getDate()+30);

    event.value = util.printd("dd/mm/yyyy", d1);

}

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 Beginner ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hello,

thank you. I have just tried that, and it did not work... I am sorry, new with this.

Date1.PNG

Date1_format.PNG

Date2.PNG

Date2_format.PNG

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 ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

You placed the code in the wrong location. It needs to go under the Calculate tab, in the third option ("Custom calculation script").

Also, if your date format is actually "mm/dd/yyyy" (and not "dd/mm/yyyy", which is what I used) then you need to change that in the code, too.

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 Beginner ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

I appreciate you! Thank you very much!

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 ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

Hello hanzCzech:

 

Did the code work for you?

I trird but di npot work for me.

 

Thanks for your help

 

Carlos

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 ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

Hello,

I used your Your code also, and it was very useful for me, thank you for this.

I have a question, please see if you can have time to help me.

In your code there is an exact number which is 30. But I put a place in my form (name is "Days") where I can write the number which I need. Then I need to use this fillabele place ("Days") instead of 30 in your code.

 

Thank you in advance.

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 ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

Sure. Just change this line of the code:

d1.setDate(d1.getDate()+30);

To this:

d1.setDate(d1.getDate()+Number(this.getField("Days").valueAsString));

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 ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

Hello Try67,

 

How will i change the code if i want to add 5 years to Date1.

Sampe is 31/01/2000 on Date1 (dd/mm/yyyy format). 

 

Date2 should have 31/01/2005

 

 

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 ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Use this:

d1.setFullYear(d1.getFullYear()+5);

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

I am trying to modify this code for +18 months.  will you assist me with this?

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

I am trying to auto caluculate an expiration date for 5 years from the date entered by the end user in a text field named "Date", formated for date d/mm/yyyy. The field for the expiration date is named "Expiration Date" and formated for date in the same way. Could you possible provide the full script for this? Thank you

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 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

The script above does exactly that...

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 ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

Hellotry67

 

Good day.

 

I tried but did not work for me, the value does not show.

 

Can you help me?

 

Thanks,

 

Carlos

 

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 ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

Check the JS Console for error messages.

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

Copy link to clipboard

Copied

This is the most succint element of code to complete this task that I've seen after spending most of today searching. THANK YOU!

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 Beginner ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

Hi,

 

Can anyone help as this does not seem to be working properly:  Im using the code but ammended to show days:

var s1 = this.getField("Date1").valueAsString;

if (s1="") event.value = "";

else {

var d1 = util.scand("dddd dd/mm/yyyy", s1);

d1.setDate(d1.getDate()+1);

event.value = util.printd("dddd dd/mm/yyyy", d1);

}

 

This is not pulling from field Date1 though, it is using the current day as input.  Can anyone see what ive done wrong?

 

tboden85_0-1692881191762.png

 

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 ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

LATEST

Are you sure this is the actual value of the field, and not just a formatted value? What does it show when you click into it?

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