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

Populate date from another field but in a different format?

New Here ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

I have 2 fields, we'll call "Date1" and "Date2". I want Date2 to automatically populate with the same date as Date1, but I want Date1 to have the format "DDMMYYYY" and Date2 to have "dd-mmm-yyyy". If I simply make the fields the same name, they will have the same date format.

I tried using the following in the custom calculation script for Date2, but it just ends up blank:

var dateVar = this.getField("Date1").valueAsDate;
if (dateVar != "") event.value = dateVar;
else event.value = "";

I also tried using "valueAsString", but then I get this error:

"Invalid date/time: please ensure that the date/time exists. Field [ Date2 ] should match format dd-mmm-yyyy"

I'm not very good with JavaScript so not sure what the right path would be here.

TOPICS
Edit and convert PDFs , JavaScript , PDF forms

Views

632

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 , Jul 14, 2021 Jul 14, 2021

You mean "Date1" have format "ddmmyyyy" not "DDMMYYYY"?

As "Validation" script of "Date1" field use this:

var f = this.getField("Date2");
if (event.value == "") f.value = "";
else {
var date = util.scand("ddmmyyyy", event.value);
f.value = util.printd("dd-mmm-yyyy", date);}

Votes

Translate

Translate
Adobe Employee ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Hi Jeremiah

 

Hope you are doing well and sorry for the trouble. The workflow you are trying to achieve is possible using the JavaScript. For more information, please check out the help article https://acrobatusers.com/tutorials/javascript_console/

 

Hope it will help

 

Regards

Amal

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 ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

You mean "Date1" have format "ddmmyyyy" not "DDMMYYYY"?

As "Validation" script of "Date1" field use this:

var f = this.getField("Date2");
if (event.value == "") f.value = "";
else {
var date = util.scand("ddmmyyyy", event.value);
f.value = util.printd("dd-mmm-yyyy", date);}

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 ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

What's the point of this line?

date.setDate(date.getDate());

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 ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

I used it for something else and forgot to delete, Fixed, thanks for pointing out 🙂

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 ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

LATEST

right again! Thanks for the help!

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