Copy link to clipboard
Copied
I have a specfic Field-1 that has a date in it. Now I want to add days to that date by looking at a number in another field-2 and using that to calculate how many days to add to the date in field-1
Example
Field-1 ( 15-Jan-2017)
Field-2 ( 6)
6 = 90 days
new date would be 15-Apr-2017
How would I do this ?
Copy link to clipboard
Copied
Date and time calculations in JavaScript are tricky. See these tutorials about the subject:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3
I've written a script that allows you to easily set up this kind of calculation, without having to write any code. It uses fixed numbers, but can be easily adjusted to use the value of a field. You can find it here: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation
Copy link to clipboard
Copied
In addition to these links, there is also the free practicalPDF Date/Time library for Acrobat: http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/
Copy link to clipboard
Copied
I figured out ( no let me rephase that) I used someone elses code to complete what I needed
(function () {
// Get date from field
var v = this.getField("Date_Completed").value;
if (v) {
// Convert string to date
var d = util.scand('dd/mmm/yyyy', v);
// Add number of days in NUMDAYS field
d.setDate(d.getDate() + +getField("NUMDAYS").value);
// Set value of this field to the new date
event.value = util.printd("dd/mmm/yyyy", d);
} else {
// Blank field if no date entered
event.value = "";
}
})();