Add X months to a defined date
Hello,
I'm a complete novice with forms, but one of my first requirements is to create a form that will calculate and display an date advanced X number of months from a defined date. For example, I enter 11/12/2018 in the defined date field, 3 in the X months field and the calculated fields should display 2/12/2019.
After some exhaustive searching in this forum and Google, I've managed to achieve some success. The following calculates and displays a date advances X number of days:
var originalDateString = this.getField("StartDate").valueAsString;
var daysString = this.getField("Offset").valueAsString;
if (originalDateString=="" || daysString=="") event.value = "";
else {
var d = util.scand("mm/dd/yyyy", originalDateString);
var days = Number(daysString);
d.setDate(d.getDate()+days);
event.value = util.printd("mm/dd/yyyy", d);
}
I can't figure out how to change from adding days to adding months. Additionally, from what I did read (but couldn't get to work) this problem is very complex. At one point, I was able to get close (have lost the link and can't find it now), but is was something like SetMonth. Well, that worked for my example above, but it the fixed date was 11/30/2018 and X = 3, the return was 03/02/2019 and not 02/28/2019.
Thanks for any help provided.
