• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Oct 25, 2017 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.5K

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
community guidelines
Community Expert ,
Oct 25, 2017 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

Votes

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
community guidelines
Community Expert ,
Oct 25, 2017 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/

Votes

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
community guidelines
Community Beginner ,
Oct 25, 2017 Oct 25, 2017

Copy link to clipboard

Copied

LATEST

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

    }

})();

Votes

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
community guidelines