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

calculating date fields for 36 months

New Here ,
Aug 17, 2023 Aug 17, 2023

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!

4.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 17, 2023 Aug 17, 2023

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 = "";
	}
}

 

 

View solution in original post

Translate
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
Community Expert ,
Aug 17, 2023 Aug 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.

Translate
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 ,
Aug 17, 2023 Aug 17, 2023

sorry - using Acrobat Pro DC

Translate
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
Community Expert ,
Aug 17, 2023 Aug 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?

Translate
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 ,
Aug 17, 2023 Aug 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

Translate
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
Community Expert ,
Aug 17, 2023 Aug 17, 2023

That works for day 17, but not 31, as Nesa correctly pointed out, and in some cases not even for 30 or 29... What if the first day is 31/01/2023? There's no 31/02/2023... Or 31/04/2023, or 31/06/2023, etc.

Translate
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 ,
Aug 17, 2023 Aug 17, 2023

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?

Translate
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
Community Expert ,
Aug 17, 2023 Aug 17, 2023

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 = "";
	}
}

 

 

Translate
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 ,
Aug 17, 2023 Aug 17, 2023

when i enter the javascript under actions is it "on blur"? (other choices are on focus, mouse up down etc)

Translate
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 ,
Aug 17, 2023 Aug 17, 2023

nevermind that one but i entered the code after viewing thumbnail and page properties, run javascript - but it won't do the other dates after i tested it. Obiously i am inputting it wrong somewhere can you walk me through it? I appreciate it.

Translate
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
Community Expert ,
Aug 17, 2023 Aug 17, 2023

try67 has posted it:

"you can use this code as the custom Validation script of the original date field"

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

I did that but the other dates are not changing?

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

Please share the file for further help.

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

Attached

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

You did not apply the code where I indicated. Also, there are errors in the JS Console when you open the file (since the code is under the Page Open action...).

The fields are not named "NextMonthX", but "Payment DateX". Also notice there are only 35 fields, starting from 2. Adjust the code accordingly.

In addition, fields 31 to 36 contain "Row" in the middle of their names, unlike the other fields. They should be renamed.

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

ill fix the code but what do you mean i didn't put code where you indicated? i thought i added the javascript to the start date?? if i didnt then can you walk me through the steps to add it there?

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

OK - i got it except for one thing  - it is skipping a month in the very beginning - it goes from 8/16/2023 to 10/16/2023 instead of 9/16/2023 - what needs to be changed - see attached

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

Change:

i=1 to i=2 since your fields start from number 2 not 1.

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

Select 'Prepare form' tool, then right click on start date field and select 'properties' then select  'Validate' tab and put script there.

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

got it but it is still skipping a month in the beginning?

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

Works fine for me. See attached.

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

this is the code i entered under validate on the start date - for me it is still skipping a month not sure why:

 

if (event.value) {
var d = util.scand("m/d/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("PAYMENT DATE"+i).value = util.printd("m/d/yyyy", d);
}
} else {
// date is after the 28th -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("PAYMENT DATE"+i).value = "";
}
}
} else {
// field is empty -> clear the other fields
for (var i=1; i<=36; i++) {
this.getField("PAYMENT DATE"+i).value = "";
}
}

 

 

Translate
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 ,
Aug 18, 2023 Aug 18, 2023

see attached - what am i doing wrong now that mine is skipping a month?

Translate
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
Community Expert ,
Aug 18, 2023 Aug 18, 2023

Read my post above.

Translate
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 ,
Aug 18, 2023 Aug 18, 2023
LATEST

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

Translate
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