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

Calculate Date on a Form

Community Beginner ,
Jan 28, 2025 Jan 28, 2025

I know this question has been asked many times. I have followed so many scripts and I keep running into the same issue and cannot figure out why.

 

I have a date field that will be user entered. I need a 2nd field to calcuate 14 days from that date.

 

The issue that I am having is when i add the script (any that I have tired) the 2nd field calculates 14 days from TODAY. even when I enter a new date in the User entered date field the calculate field will not change. 

 

Very frustrating! (Note I am Not a coder this is new to me... pls be kind) I hope someone can help!

Screenshot 2025-01-28 at 12.02.43 PM.pngScreenshot 2025-01-28 at 11.48.17 AM.pngScreenshot 2025-01-28 at 12.02.54 PM.pngScreenshot 2025-01-28 at 12.03.13 PM.png

TOPICS
PDF forms
607
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
1 ACCEPTED SOLUTION
Community Beginner ,
Jan 28, 2025 Jan 28, 2025

Ok so idk what i did but ultimately got it to work! this was the code i used in case it can help anyone... 

Thank you everyone who tried to help!!

 

var d = util.scand("dd/mm/yy", this.getField("NewLatestShippingDate").valueAsString);

var theTime = d.getTime () ; var oneDay = theTime + 14*24*3600*1000;

var dd = new Date(oneDay); event.value = util.printd("dd/mm/yy", dd)

View solution in original post

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 Expert ,
Jan 28, 2025 Jan 28, 2025

Which field is your script in and what type of script (calculation/validation)?

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 Expert ,
Jan 28, 2025 Jan 28, 2025

Check that field is not empty before setting date:

var f = this.getField("NewLatestShippingDate").valueAsString;
var d = util.scand("dd/mm/yyyy", f);

if(f !== ""){
 d.setDate(d.getDate()+14);
 event.value = util.printd("dd/mm/yyyy", d);}
else
 event.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 ,
Jan 28, 2025 Jan 28, 2025

Ok so idk what i did but ultimately got it to work! this was the code i used in case it can help anyone... 

Thank you everyone who tried to help!!

 

var d = util.scand("dd/mm/yy", this.getField("NewLatestShippingDate").valueAsString);

var theTime = d.getTime () ; var oneDay = theTime + 14*24*3600*1000;

var dd = new Date(oneDay); event.value = util.printd("dd/mm/yy", dd)

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
Adobe Employee ,
Mar 03, 2025 Mar 03, 2025
LATEST

Thank you for sharing the steps and code, Joan. This will definitely help other community members. For future reference, you can refer to this article: Adobe Acrobat JavaScript Developer Guide.

 

~Anand Sri.

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