Skip to main content
Participating Frequently
August 17, 2023
Answered

calculating date fields for 36 months

  • August 17, 2023
  • 2 replies
  • 6035 views

Maybe someone here can help - 

 

I am trying to create a schedule of dates that would start on a date that I enter and then every subsequent date would be exactly the same day the following month for 36 consecutive months.

For example if the first date is 8/17/2023, then it would automatically fill the rest at 9/17/2023, 10/17/2023 etc for a total of 36 months. 

Can someone please explain how i can do this?

 

Much Appreciated!

    This topic has been closed for replies.
    Correct answer try67

    yes, i get that - but if i wanted to do it for all dates before the 28th, I could create a separate template to manually input if the first date is the 29th, 30th, or 31st. It would still make things easier if i had 2 schedules where at least one of them I could have the dates input as i stated and then the other manual as I am currently doing. Can you show me a way to do what I am looking for up to the 28th?


    OK. In that case, assuming the fields are named NextMonth1-NextMonth36, you can use this code as the custom Validation script of the original date field:

     

    if (event.value) {
    	var d = util.scand("mm/dd/yyyy", event.value);
    	if (d.getDate()<=28) {
    		// data is before (or equal to) the 28th -> populate the other fields
    		for (var i=1; i<=36; i++) {
    			d.setMonth(d.getMonth()+1);
    			this.getField("NextMonth"+i).value = util.printd("mm/dd/yyyy", d);
    		}
    	} else {
    		// date is after the 28th -> clear the other fields
    		for (var i=1; i<=36; i++) {
    			this.getField("NextMonth"+i).value = "";
    		}
    	}
    } else {
    	// field is empty -> clear the other fields
    	for (var i=1; i<=36; i++) {
    		this.getField("NextMonth"+i).value = "";
    	}
    }

     

     

    2 replies

    Nesa Nurani
    Community Expert
    Community Expert
    August 17, 2023

    What if entered date is 31st and next month has 30 days what should be date in that case day before or day after?

    Participating Frequently
    August 17, 2023

    Nesa,

     

    I don't want it like that if you see the example, it has to be the same day on each month - so if the 1st date is 8/17/2023, then the next date is 9/17/23 and so on - Thanks

    Participating Frequently
    August 18, 2023

    Read my post above.


    Got it! i missed your post Nesa where you said to change i to =2. Thank you both so much - this will make it much easier for me. I really appreciate both you and your patience with me. Thanks again

    Peru Bob
    Community Expert
    Community Expert
    August 17, 2023

    This is the Using the Community forum (which is the forum for issues using the forums).
    Please tell us what Adobe application you are using so that this can be moved to the proper forum for help.

    Participating Frequently
    August 17, 2023

    sorry - using Acrobat Pro DC