Instead of using the milliseconds, one can use the various "get" and "set" methods of the date object. We can start out with adding 9 months to the current date by converting the starting date string to the date object using the "util.scand" method. Next we can obtain the current month using the "getMoth()" method. We can now add 9 months using the current month value plus 9 in the "setMonth" method. Now we can use the undocumented trick of add 1 more month the to the date of the month and setting the date value to zero to get the last day of a month. We just now need to format the adjusted date object to the display format of the date using the "util.printd" method. To get to the 1 year value we can add 3 months to computed date object. To get to the 21 months we add another 9 months to the date object. And to get to 2 years we add another 3 months for a total of 24 months.
Assuming a date format of "d-mmm-yyyy" and field names of "NineMonths", "OneYear", "TwentyOneMonths" and "TwoYears" for the various result fields we can use the "On Blur" action for the inputted date field with the following script:
// for JavaScript date object, month end for a month is next month date 0;
// this can be used in the getMonth method to set the date to the end of the current month;
var cDate = event.value;
if(cDate != "")
{
var cFormat = "d-mmm-yyyy";
// get date object;
var oDate = util.scand(cFormat, cDate);
// 9 months;
// month end plus 9 months;
oDate.setMonth(oDate.getMonth() + 1 + 9, 0);
// month end plus 9 months;
this.getField("NineMonths").value = util.printd(cFormat, oDate);
// 1 year;
// month end plus 1 year;
oDate.setMonth(oDate.getMonth() + 1 + 3, 0)
this.getField("OneYear").value = util.printd(cFormat, oDate);
// 21 months;
//month end 21 months;
oDate.setMonth(oDate.getMonth() + 1 + 9, 0);
this.getField("TwentyOneMonths").value = util.printd(cFormat, oDate);
// 2 years;
// month end plus 2 years;
oDate.setMonth(oDate.getMonth() + 1 + 3, 0);
this.getField("TwoYears").value = util.printd(cFormat, oDate);
}
The above script will adjust the the end of the month for any date in February 2018 to February 29 2020 for the date plus 2 years.