Calcuate AGE from DOB, Update Age Automatically
OK, so I'm trying to use a custom calculation script, tied to my AGE field to calculate age from the DOB field. The format of the AGE field is set to None and the format of the DOB field is set to Date, mm/dd/yyyy. This is the script I was working with and which I thought was working, but I see now it doesn't work for me when the DOB is 05/30/1926. Can someone please correct my script so it works and automatically updates the AGE field every time the PDF is opened, printed, or saved?
Here is my current script:
event.value = "";
dobValue = getField("DOB").value;
if (dobValue!="") {
dob = util.scand("dd/mm/yyyy", dobValue);
today = new Date();
// compute using year
event.value = today.getFullYear() - dob.getFullYear();
// adjust when today's month is before dob's month
event.value = event.value - (today.getMonth() < dob.getMonth() ) * 1;
// adjust when months are equal and date is before dob's date
event.value -= ( (today.getMonth() == dob.getMonth() ) && (today.getDate() < dob.getDate() ) ) * 1
}
I realize there are already several posts out there about this, but I've not found anything yet that resolves my issue and would love the help making this work! Thanks in advance for your time and attention!
