Skip to main content
Participant
February 6, 2024
Question

Date conversion

  • February 6, 2024
  • 2 replies
  • 571 views

I want to convert the date YYMMDD,  240206 to a number then add 10 to each of the year month and day.

So 341216.

 

Any advice as to where I can find a resource for this?

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
February 6, 2024

There is no such date format. I think you mean "yymmdd".  

There are several ways to manipulate dates. There's the Acrobat JavaScript date functions util.scand() and util.printd(). Then there are the Core JS Date functions. 

 

But for your case the easiest method is just to split the string into 3 two digit sections and convert them to numbers.  There are also several ways to do this. I'd use a regular expression.

 

if(/^(\d{2})(\d{2})(\d{2})$/.test(strDateText))

{

      strRslt = (Number(RegExp.$1) + 10).toString()) + 

                     (Number(RegExp.$2) + 10).toString()) + 

                     (Number(RegExp.$3) + 10).toString());

}

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
February 6, 2024

Number(util.printd("yymmdd", new Date())) + 101010