Skip to main content
Inspiring
December 11, 2023
Question

date format

  • December 11, 2023
  • 1 reply
  • 552 views

hi
I created this code to copy the date entered in the "PURCHASE DATE" field with mm/yy format.
I inserted the formula in the calculation script of the "DATA_2" field
var s1 = this.getField("PURCHASE DATE").value;
if (s1 !== "") {var a1 = s1.replace(/\//g, '');
var b1 = util.scand("mmyy", a1);
event.value = util.printd("mm yy", b1);}
else {event.value = "";}

the console message is:
TypeError: Invalid argument type.
Util.printd:4:Console undefined:Exec
===> oDate parameter.

Please, can anyone help me find the solution?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
December 11, 2023

I'd have to see the test values, but util.scand() is probably returning null because the input is either ambigous or doesn't match. Why did you remove the "/"?  the slash removes ambigouity. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ENE5CD9Author
Inspiring
December 11, 2023

I found the error
the "PURCHASE DATE" field was ddmmyyyy and not mmyy
Thank you very much

Thom Parker
Community Expert
Community Expert
December 11, 2023

So the input didn't match the specified format. Definately an issue, and something that could be checked with a regular expression before proceeding with the script. 

 

However, it is also a problem to not have separators in the date string. The separators make recognition of the date elements explicit. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often