Skip to main content
Participant
November 1, 2020
Question

Multiple date fields in pdf form but with different formats

  • November 1, 2020
  • 2 replies
  • 703 views

I am creating a pdf form which has a date field (Date1).  The same date field needs to appear as "mmmm dd, yyyy", "mm/dd/yyyy" and "yyyy-mm-dd" within the form.  I want to change the date one time and have it update across the form using the various formats.  

 

I found a post at 

https://community.adobe.com/t5/acrobat/copy-date-to-field-with-different-formatting/td-p/10648920 

which addresses the issue.  I don't know Javascript but tried using the second suggested code:

 

You can also just try this line in the custom calculation script of BrthDate2 field:

var s = this.getField("BirthDate").valueAsString;      <<<----------------------------NOTE THE USE OF valueAsString instead of .value
if (s=="") event.value = "";
else {
var d = util.scand("dd-mm-yyyy", s);
d.setDate(d.getDate()-0);
event.value = util.printd("dd/mmm/yyyy", d);
}

 

The second instance of the date (3Date) works as expected using:

var s = this.getField("Date1").valueAsString;
if (s=="") event.value = "";
else {
var d = util.scand("mm/dd/yyyy", s);
d.setDate(d.getDate()-0);
event.value = util.printd("mm/dd/yyyy", d);
}

 

BUT I cannot get the 3rd instance (Date4) to work.  What am I missing?  Below is the Custom Calculation Script:

 

var s = this.getField("Date1").valueAsString;
if (s=="") event.value = "";
else {
var d = util.scand("yyyy-mm-dd", s);
d.setDate(d.getDate()-0);
event.value = util.printd("yyyy-mm-dd", d);
}

 

 

 

 

Likes

 
This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
November 1, 2020

You keep using different formats for the scand method which parses the value of Date1. That doesn't make sense. You need to specify the right format string for that field, and then it will work. Oh, and these lines can be removed, as they don't do anything:

d.setDate(d.getDate()-0);

Bernd Alheit
Community Expert
Community Expert
November 1, 2020

What date format does you at Date1 and Date4?

Participant
November 1, 2020

Thanks for your reply.

 

Date1 is mmmm d, yyyy

3Date is mm/dd/yyyy

Date4 is mm-dd-yyyy

 

When Date1 is changed to another date, 3Date updates to the same date as expected with mm/dd/yyyy format

Date4 does not update at all.

 

 

Bernd Alheit
Community Expert
Community Expert
November 1, 2020

You must change the date format at util.scand.