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

Trying to define a period of time as qualification for a user defined date

New Here ,
Oct 31, 2020 Oct 31, 2020

Copy link to clipboard

Copied

Im trying to return either "Qualified" or "Too early for qualification" from a user defined date. 

Qualification occurs if the user defined date is gretaer than a specified date.

I have limited scripting knowledge but I am missing something

 

var 1A = (this.getField("installation date").value);

if 1A> date (2017,5,19) event.value = "Qualified";

else if 1A< date (2017,5,19) event.value = "Too early for qualification";

}

Can anyone help?

TOPICS
PDF forms

Views

363

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

Community Expert , Oct 31, 2020 Oct 31, 2020

You can try it out like this:

 

 

var A1 = this.getField("installation date").valueAsString;

if (A1.length !=="") {

  var userDefinedDate = util.scand("yyyy,m,dd", A1);
  var specifiedDate = "2017,5,19"
  var QualificationDate = util.scand("yyyy,m,dd", specifiedDate)


if ( userDefinedDate.getTime() <=  QualificationDate.getTime() ) {event.value = "Too early for qualification";}

if ( userDefinedDate.getTime() > QualificationDate.getTime() ) {event.value = "Qualified";}
} 

if (A1 =="") event.
...

Votes

Translate

Translate
Community Expert ,
Oct 31, 2020 Oct 31, 2020

Copy link to clipboard

Copied

You can try it out like this:

 

 

var A1 = this.getField("installation date").valueAsString;

if (A1.length !=="") {

  var userDefinedDate = util.scand("yyyy,m,dd", A1);
  var specifiedDate = "2017,5,19"
  var QualificationDate = util.scand("yyyy,m,dd", specifiedDate)


if ( userDefinedDate.getTime() <=  QualificationDate.getTime() ) {event.value = "Too early for qualification";}

if ( userDefinedDate.getTime() > QualificationDate.getTime() ) {event.value = "Qualified";}
} 

if (A1 =="") event.value ="";

 

 

You need to use the scand method first in order to convert the date string value  to an date object.  This, of course, can be achieved in many ways using JavaScript date arithmetic. But in my example above I preferred to parse the date arithmetic by converting the defined date string ("2017,5,19") to an date object and compare the difference between two date objects in milliseconds. In my personal opinion, and as I continue to learn JavaScript scripting, this method provides a very accurate results (but I am sure there are other ways too).

 

This is referenced in greater detail in the Adobe Acrobat DC SDK, Using JavaScript in Forms, 
Developing Acrobat® Applications Using JavaScript™,  "Date arithmetic", Page 94

 

Specifically in the following section:

 

  • "  Date arithmetic
    It is often useful to do arithmetic on dates to determine things like the time interval between two dates or what the date will be several days or weeks in the future. The JavaScript Date object provides several ways to do this. The simplest and possibly most easily understood method is by manipulating dates in terms of their numeric representation. Internally, JavaScript dates are stored as the number of milliseconds (one thousand milliseconds is one whole second) since a fixed date and time. This number can be retrieved through the valueOf method of the Date object. The Date constructor allows the construction of a new date from this number."

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 Expert ,
Oct 31, 2020 Oct 31, 2020

Copy link to clipboard

Copied

Small nitpick... Change this line:

if (A1.length !=="") {

To:

if (A1!=="") {

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 Expert ,
Oct 31, 2020 Oct 31, 2020

Copy link to clipboard

Copied

Thank you !

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
New Here ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

LATEST

Incredible to have been responded to and amazingly fast. I appreciate it. That was my first foray onto this forum and you nailed my query from the getgo. Thanks for your help, it works of course it does, and for your explanation. 

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