Highlighted

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

New Here ,
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?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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."
TOPICS
PDF forms

Views

33

Likes

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

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

New Here ,
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?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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."
TOPICS
PDF forms

Views

34

Likes

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
Oct 31, 2020 0
Adobe Community Professional ,
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."

Likes

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
Reply
Loading...
Oct 31, 2020 1
Most Valuable Participant ,
Oct 31, 2020

Copy link to clipboard

Copied

Small nitpick... Change this line:

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

To:

if (A1!=="") {

Likes

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
Reply
Loading...
Oct 31, 2020 1
Adobe Community Professional ,
Oct 31, 2020

Copy link to clipboard

Copied

Thank you !

Likes

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
Reply
Loading...
Oct 31, 2020 1
cdcg31 LATEST
New Here ,
Nov 01, 2020

Copy link to clipboard

Copied

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. 

Likes

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
Reply
Loading...
Nov 01, 2020 1