Copy link to clipboard
Copied
I have a form with two manual dates entered. Later in the form, I need to return a date 30 days later than the earliest of the two dates. How do I program the form to do this?
Copy link to clipboard
Copied
You will need to use custom JavaScript. The question each of finding earliest date and add days or other period have been asked and entered many many times. You will need to convert the date strings values of the 2 fields to a JavaScript date object, you can use the "util.scand()" method., You can get the earliest date by comparing the results of the "getTime()" method of the date object. You can use the "getDate()" and ".setdate()" to add 30 days to the selected date object. You can then use Acrobat's "util.printd()" method to format the result.
Copy link to clipboard
Copied
Thank you, this sounds very technical and I am a amateur. Can you please walk me through it?
Copy link to clipboard
Copied
I was able to find someone who could help me, and this is the custom calculation script that was created for anyone else who may have the same issue (it works)!
// Custom calculate script for "31ST DAY" field
(function () {
// Get date from field
var v = getField("ORIGINAL DISPENSE DATE").valueAsString;
// Get date from field
var x = getField("DATE DISPENSED").valueAsString;
// Convert string to date
var d = util.scand("mm/dd/yy", v);
// Convert string to date
var dx = util.scand("mm/dd/yy", x);
// Populate this field with the result
if (v) {
// Add 30 days
d.setDate(d.getDate() + 30);
event.value = util.printd("mm/dd/yy", d);
} else {
if (x ) {
// Add 30 days
dx.setDate(dx.getDate() + 30);
event.value = util.printd("mm/dd/yy", dx);
} else {
event.value = "";
}
}
})();
Copy link to clipboard
Copied
Thx, I used this procedure as best I could to calculate the 56th day for purpooses of the PPP Loan Forgiveness Application.
But ran into a small problem, that I can deal with: when the beginning date field is empty, then my result field is the last value, and I'd like for it to be a blank field, below is the script that I entered:
var v = getField("COVERED_PERIOD").valueAsString;
// Convert string to date
var d = util.scand("mm/dd/yy", v);
// Add 30 days
d.setDate(d.getDate() + 56);
event.value = util.printd("mm/dd/yyyy", d);
Any suggestions?
Thx in advance
Copy link to clipboard
Copied
You need to test the input to the process
var v = getField("COVERED_PERIOD").valueAsString;
if(/\d{1,2}\/\d{1,2}\/\d{4}/test(v))
{
.. rest of script
}
else
event.value = "";
Copy link to clipboard
Copied
How would I have it calculate a date for 2 years in the future? Example, contract signed date plus 2 years to show the from date (date signed) to the "to" date (date 2 years later when it expires).
Copy link to clipboard
Copied
Let's say you have the fields named "Date1" and "Date2" and you wish to set "Date2" to be two years from whatever is entered in "Date1".
Use this as 'Validate' script of "Date1" field:
var date2 = this.getField("Date2");
if(event.value == "")
date2.value = "";
else{
var date1 = util.scand("mm/dd/yyyy", event.value);
date1.setFullYear(date1.getFullYear()+2);
date2.value = util.printd("mm/dd/yyyy", date1);}