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

AGE Calculation Help!

Tomme
Registered: Jun 2 2011
Posts: 11

I have read post after post after post and can still not get an AGE to calculate when a date is placed in a field. I am EXTREMELY new to this and feel defeated already. I know there are a lot of posts about this, but I am still not grasping it.
I need the age to go into a field titled "AGE" that is calculated from a date of birth field titled "DOB"
I have the current date being automatically filled in when the PDF opens in a field titled "DOS3"
 
I need some help! I am just a fireman, this is FAR above my pay grade! I am using Adobe Professional 9 (I think).

JoelGeraci
ExpertTeam
Registered: Aug 17 2006
Posts: 80
This would be a good place to start.

http://www.pdfscripting.com/public/department44.cfm

J-
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Here's the custom calculation code for AGE (make sure you set DOB to have the Date format):

event.value = "";
dobValue = getField("DOB").value;
if (dobValue!="") {
dob = new Date(dobValue);
now = new Date();
age = now.getFullYear() - dob.getFullYear();
if (now.getMonth() < dob.getMonth())
age--;
else if (now.getMonth()==dob.getMonth() && now.getDate() < dob.getDate())
age--;
event.value = age;
}

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

Tomme
Registered: Jun 2 2011
Posts: 11
This still is not working. I have two DOB fields, so that when I type a date of birth into one, it copies to another page as well. I named them both "DOB" and made them both MM/DD/YYYY. In my "age" field I set the Action to MOUSE UP, Run a JAVASCRIPT, and pasted your script in.

WHAT AM I MISSING?

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Are there any error messages in the console?
What do you see in the age field?

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

Tomme
Registered: Jun 2 2011
Posts: 11
NEVERMIND! I finally figured it out. THANKS!