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.
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);}
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
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);}
Copy link to clipboard
Copied
What's the point of this line?
date.setDate(date.getDate());
Copy link to clipboard
Copied
I used it for something else and forgot to delete, Fixed, thanks for pointing out 🙂
Copy link to clipboard
Copied
right again! Thanks for the help!