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

Spit MM,DD,YYYY in two fields?

Community Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

Good afternoon,

Is there a way to split MM,DD,YYYY in two fields where the month is spelled out (can be any month of the year)? A previous thread showed me how to slice the characters in two (for example) fields but i don't know how it can be used since value.length varies depending on number of characters in a month. Is there light at the end for this scenario?

Example: March 14, 2016

Field1: March 14

Field2: 2016

Where the number of characters in month varies.

Thanks,

Edgar A.

TOPICS
Acrobat SDK and JavaScript

Views

1.0K

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

Advocate , May 10, 2016 May 10, 2016

The Date object is not described in the Acrobat JavaScript documentation (because it is part of the JavaScript Core). However, you will find good descriptions online (or, if you are serious, get Flanagan's book JavaScript, the ultimate Guide, published by O'Reilly).

Acrobat JavaScript has not only the util.prind() method, but also the util.scand(), which takes a string (which should represent a date), and creates a valid Date object from that string's value and the format string.

So, if you have a

...

Votes

Translate

Translate
Advocate ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

That could be done with a little bit of (Acrobat) JavaScript:

Let's assume that the field for month and date is named dat.month, and the field for the year dat.year.

You somehow provide the date to be used, and pass it as a Date Object "theDay"

In the general calculation script, you would then add the following two lines of code:

this.getField("dat.month").value = util.printd("mmmm d", theDay) ;

this.getField("dat.year").value = util.printd("yyyy", theDay) ;

And that would do it.

As said, you would have to create the proper date object.

Hope this can 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
Community Beginner ,
May 10, 2016 May 10, 2016

Copy link to clipboard

Copied

maxwyss, will this work if the date can be any day of the year and not necessarily today's date? I'm currently researching more about "date ojbject" but i'm starting to get the gist. The PDF form is generated by the Interface. The user will select (for example) a product and that product was purchased on a particular date.

One more thing. The interface will import the date already formatted... Such as January 14, 2016. But I also have the ability to import it as 01/14/2016 if it helps.

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
Advocate ,
May 10, 2016 May 10, 2016

Copy link to clipboard

Copied

The Date object is not described in the Acrobat JavaScript documentation (because it is part of the JavaScript Core). However, you will find good descriptions online (or, if you are serious, get Flanagan's book JavaScript, the ultimate Guide, published by O'Reilly).

Acrobat JavaScript has not only the util.prind() method, but also the util.scand(), which takes a string (which should represent a date), and creates a valid Date object from that string's value and the format string.

So, if you have a field with a value 01/14/2016, the format string would be mm/dd/yyyy, and the code to create a Date object

var myDate = util.scand("mm/dd/yyyy", this.getField("myField").valueAsString) ;

And based on that, you can get quite a bit of input working (note that this is a single line of code).

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 Beginner ,
May 11, 2016 May 11, 2016

Copy link to clipboard

Copied

LATEST

maxwyss, Assuming your male, Man hug coming your way! This worked perfectly!

I added the following.

var myDate = util.scand("mm/dd/yyyy", this.getField("GLOBAL__POSTING_DATE").valueAsString) ;

this.getField("month1").value = util.printd("mmmm d", myDate) ;

this.getField("year1").value = util.printd("yyyy", myDate) ;

I noticed today's date auto populates the second i close the properties field. But it gets overwritten when I enter a random date. So i added the following to keep the field null until I entered a date. I'm not the sharpest tool but it worked LOL.

if (myDate!="")

{event.value=myDate;}

I just ordered Flanagan's book JavaScript. But can you suggest a beginner's handbook (for dummies)?? So I can crawl before I walk.

Thanks,

Ed

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