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

New Here ,
Oct 25, 2017

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 ?

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.2K

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

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

New Here ,
Oct 25, 2017

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 ?

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.2K

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 25, 2017 0
Most Valuable Participant ,
Oct 25, 2017

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

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 25, 2017 0
Adobe Community Professional ,
Oct 25, 2017

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/

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 25, 2017 0
New Here ,
Oct 25, 2017

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

    }

})();

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 25, 2017 0