Skip to main content
Participant
May 17, 2024
Question

Add X months field to a defined date

  • May 17, 2024
  • 2 replies
  • 594 views

I'm trying to create a custom calculation script in adobe acrobat pro to do the following:

 

Commencement date field - enter date

Term field - enter number of months - for example 6 months

End date - calculate by taking the commencement date and adding the number of months specified in the term field.

 

Here's what I currently have - the month changes depending on whats in the term field but for some reason it's added 4 year so to the end date. What do I need to change for this script to work. Many thanks in advance for any ones help 🙏


var getMonth = this.getMonth("TERM"); var strDate = this.getField("COMMENCEMENT DATE").valueAsString; // Test for date format if (/\d{1,2}\/\d{1,2}\/\d{2}/.test(strDate)) { var dt= util.scand("dd/mm/yyyy", strDate); dt.setMonth(dt.getMonth()+getMonth); dt.setDate(dt.getDate()-1); event.value=util.printd("dd/mm/yyyy",dt) } else {event.value=""}

 

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
May 17, 2024

The first line of your code doesn't make sense. If you're trying to access a field you need to use getField, and naming a variable the same as a method of the Date object is a bad idea, as was mentioned above.

Bernd Alheit
Community Expert
Community Expert
May 17, 2024

Try this:

change the name of variable getMonth.