These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculate months

paulaeddy
Registered: May 14 2010
Posts: 22

Is there any way to calculate months? I have two dates: Month1 and Month2. What I need is to fill in blanks with the months and months in between of which will never be more than a year apart.
 
First Example:
Month1 = February
Month2 = June
 
There are 12 blanks. I would need the first five blanks to be populated with February, March, April, May, and June.
  
Second Example:
Month1 = March
Month2 = February
 
Again, there are 12 blanks. I would need all 12 blanks with the consecutive months starting with March.
 
Any idea? Thanks!

My Product Information:
Acrobat Pro 9.4.2, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Have you thought of using a combo box to select the first month only and then fill in the next 11 text fields with the appropriate month?

There are some interesting things that can be done with the date object and the 'util.printd()' method.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
George, that's not what he wants to achieve, I think. He want the text fields to be filled with the months between the first one and the second one. However, I do think that using combo-boxes would make it easier to implement. I might post some code later on.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

try67
Expert
Registered: Oct 30 2008
Posts: 2398
OK, so I'm assuming the following:
- You have two combo-boxes ("Month1" and "Month2") with the months as values and 1 through 12 as export values.
- You have a set of 12 text fields named "MonthText1" to "MonthText12".

You can then use this script to populate your text boxes:

month1 = this.getField("Month1").value;
month2 = this.getField("Month2").value;

if (month1!="" && month2!="") {
if (month1>month2) {
var index = 1;
for (i=month1; i<=12; i++) {
date1 = util.scand("dd/mm/yyyy", "01/" + i + "/" + new Date().getFullYear());
this.getField("MonthText"+index).value = util.printd("mmmm", date1);
index++;
}for (i=1; i<=month2; i++) {
date1 = util.scand("dd/mm/yyyy", "01/" + i + "/" + (new Date().getFullYear()+1));
this.getField("MonthText"+index).value = util.printd("mmmm", date1);
index++;
}} else {
var index = 1;
for (i=month1; i<=month2; i++) {
date1 = util.scand("dd/mm/yyyy", "01/" + i + "/" + new Date().getFullYear());
this.getField("MonthText"+index).value = util.printd("mmmm", date1);
index++;
}
}
} else {
for (i=1; i<=12; i++) {
this.getField("MonthText"+index).value = "";
}
}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

paulaeddy
Registered: May 14 2010
Posts: 22
Thanks try67,

This works well. Just a couple of things...

1) If the range is less than 12 months from Month1 to Month2, then the remaining months are unchanged from the previous month inputs.

2) Is it possible to put some formula in there to only populate the months in the range? For example, if it is from October 2010 to February 2011, I would like for the MonthText fields to populate only 5 months (October, November, December, January, February) and the rest of the MonthText fields to be blank.

If it helps, there are two other fields available: Year1 and Year2 that coincide with Month1 and Month2.

Thanks so much!