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?
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.
...
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:
Copy link to clipboard
Copied
Small nitpick... Change this line:
if (A1.length !=="") {
To:
if (A1!=="") {
Copy link to clipboard
Copied
Thank you !
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.