Skip to main content
johnh91582287
Participant
October 25, 2017
Question

Add days to a specific date. Using a various groups of days

  • October 25, 2017
  • 2 replies
  • 1656 views

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 ?

This topic has been closed for replies.

2 replies

johnh91582287
Participant
October 25, 2017

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 = "";

    }

})();

try67
Community Expert
Community Expert
October 25, 2017

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

Karl Heinz  Kremer
Community Expert
Community Expert
October 25, 2017

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/