Age calculation in months or years
I am using a calculation script to calculate age from a DOB field. It works just fine for the calculation and I can manipulate it to calc either in months or years. The problem is I want to have any ages < 1 year old to show the age in months and ages > 1 year old to show the age in years. Hopefully that makes sense. I have been searching through the existing threads and can't seem to find anything to help this specific need. If there a way to do this - maybe an additional IF clause? Here is my current calculation script.
event.value = "";
var dobValue = getField("Kid.DOB").value;
if (dobValue!="") {
var dob = util.scand("mm/dd/yyyy", dobValue);
var today = new Date();
// compute age in milliseconds
var age = today.getTime() - dob.getTime();
// convert age to years ( millsec in sec * sec in min * min in hrs * hrs in day * days in year)
// truncate to whole years and adjust for binary floating point error
event.value = Math.floor( age / (1000 * 60 * 60 * 24 * 365.2425) - 0.005);
}
If I want calculate in months, I change the 365.2425 to 30.436.
