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

Compute a future date using "StartDate" field adding "NumberOf Months" field value to get "EndDate"

New Here ,
Oct 20, 2019 Oct 20, 2019

Copy link to clipboard

Copied

How do I compute an "EndDate" by adding the number of months in field "AgreementMonths" to a date in "StartDate".

The fields are StartDate, AgreementMonths and EndDate.

Dates are formatted October 19, 2019 (mmmm d, yyyy)

StartDate + AgreementMonths = EndDate

TOPICS
PDF forms

Views

730

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

correct answers 1 Correct answer

LEGEND , Oct 20, 2019 Oct 20, 2019

Date calculations are done using JavaScript custom calculations or actions. Date calculations or formatting cannot be done in the Simplified field notation or any of the "field value is the __________ of the following fields.  All string date values need to be converted to thed JavaScript Date object. Adobe has provided some documentation about Using the Date Object and performing Date arithmetic.

 It is easiest to convert date strngs to a Date object by using the util.scand method. This method

...

Votes

Translate

Translate
LEGEND ,
Oct 20, 2019 Oct 20, 2019

Copy link to clipboard

Copied

Date calculations are done using JavaScript custom calculations or actions. Date calculations or formatting cannot be done in the Simplified field notation or any of the "field value is the __________ of the following fields.  All string date values need to be converted to thed JavaScript Date object. Adobe has provided some documentation about Using the Date Object and performing Date arithmetic.

 It is easiest to convert date strngs to a Date object by using the util.scand method. This method will report an invalid date string by returning  a null value.  One can use JavaScript to manipulate date objects and extract data from the Date object. One can get the fullYear, month, day, hour, minute, second, and  milliseconds as well as set them.

 

Taking all the above, one can use for dates with the format of "d-mmm-yyyy".

 

// custom calculation script for EndDate;
// get start date string;
var cStartDate = this.getField("StartDate").valueAsString;
// convert date string to date object;
var oStartDate = util.scand("d-mmm-yyyy", cStartDate);
// set date time to midnight by setting seconds and milliseconds to 0;
oStartDate.setSeconds(0, 0);
if(oStartDate == null) {
app.alert("Date Converstion Error start date " + cStartDate, 1, 0);
}
// get length of agreement in months;
var nAgreementMonths = this.getField("AgreementMonths").value;
// set end date to start date plus lenght of agreements in months;
var oEndDate = oStartDate;
oEndDate.setMonth(oEndDate.getMonth() + nAgreementMonths);
// set field value to formatted comuted end date;
event.value = util.printd("d-mmm-yyyy", oEndDate);

 

Note JavaScript does not use the last day of the month but the number of days in the start month.

 

 

 

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
New Here ,
Oct 20, 2019 Oct 20, 2019

Copy link to clipboard

Copied

LATEST

Works perfectly.

I haven't used JavaScript but will definitely begin learning it.

Thanks

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