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

Add month(s) to date, not to exceed the last day of the next month

New Here ,
May 04, 2018 May 04, 2018

Copy link to clipboard


I'm trying to add one or more months to a date field, but I'm running into an issue with the end of the month. If "today" is 01/31/2018, and I add one month, I would like the result to be 02/29/2018, but instead I get 03/03/2018.

Is there a way to calculate this, check to see if the date matches, and if it doesn't, set the date at the end of the previous month? In my example, 31!=3, so set the date at 02/29/2018 instead of 03/03/2018.

Here's the script that I'm using:

todayString = this.getField("today").valueAsString;

var months = Number(this.getField("months").valueAsString);

if (todayString=="" || months==0) event.value = "";

else {   

    var d = util.scand("dd.mm.yyyy", startDateString);


    event.value = util.printd("dd.mm.yyyy", d);


Acrobat SDK and JavaScript







Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation