For a rough approximation, divide by 365.25.
For the whole shooting match in AcroForms JavaScript:
function DateDiff(oEndDate, oStartDate) {
/*
Purpose: compute the years, months and days that
have elapsed between the passed start and end dates.
Inputs:
oEndDate - JavaScript date object for the end date
oStartDate - JavaScript date object for the start date
Returns: array containing the years, months and days that have elapsed.
Notes: the JavaScript date/time object is used so the function
does not need to resolve the various date formats.
*/
// array for number days in a month for the current year - zero based array rows and columns
var aDaysMonth = new Array(
31, 28, 31,
30, 31, 30,
31, 31, 30,
31, 30, 31
);
// adjust number of days in a month for leap century and leap year
if ((oEndDate.getYear() % 4) == 0) // leap
aDaysMonth[1][0] = 29; // leap year then February has 29 days
if (((oEndDate.getFullYear() % 400) != 0) & (oEndDate.getYear() == 0)) // check not leap century
aDaysMonth[1][0] = 28; // if century is not a leap century then February has 28 days
var endYear = oEndDate.getFullYear(); // get the full year from the end date object
var endMonth = oEndDate.getMonth(); // get the zero based month from the end date object
var endDate = oEndDate.getDate(); // get the date from the end date object
var startYear = oStartDate.getFullYear(); // get the full year from the start date object
var startMonth = oStartDate.getMonth(); // get the zero based month from the start date object
var startDate = oStartDate.getDate(); // get the date from the start date object
var diffYear = endYear - startYear;
var diffMonth = endMonth - startMonth;
var diffDate = endDate - startDate;
// see if need to borrow from month
if (diffDate < 0) {
diffDate = diffDate + aDaysMonth[startMonth]; // add number of days for start date's month
--diffMonth; // de cress start month by one
}
// see if need to borrow from Year
if (diffMonth < 0) {
diffMonth += 12; // add 12 months to diffMonth
--diffYear; // decrease 1 year
} // end if diffMonth < 0
return [diffYear, diffMonth, diffDate];
} // end function DateDiff
// get the age array element [0] is years, [1] is months, and [2] is days.
var aAge = DateDiff( new Date(), util.scand("mm/dd/yyyy", this.getField("birthdate").value) );
event.value = "Your age is: " + aAge[0] + " years " + aAge[1] + " months " + aAge[2] + " days.";
/* Example of date arithmetic. */
console.show();
console.clear();
/* Create a Date object with a definite date. */
var d1 = util.scand("mm/dd/yyyy", this.getField('birthdate').value);
/* Create a date object containing the current date. */
var d2 = new Date();
/* Number of seconds difference. */
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
/* Print some interesting stuff to the console. */
console.println("It has been " + diff + " seconds since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " + diff / 60 + " minutes since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " + (diff / 60) / 60 + " hours since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " +
((diff / 60) / 60) / 24 + " days since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " +
Math.floor(((diff / 60) / 60) / 24) + " days since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " +
Math.floor(((diff / 60) / 60) / 24) / 365 + " 365 day years since " + util.printd("mm/dd/yyyy", d2));
console.println("It has been " +
Math.floor(((diff / 60) / 60) / 24) / 365 + " 365.25 years since " + util.printd("mm/dd/yyyy", d2));
The above can be converted LiveCycel Desigenr JavaScript.
For a workin example:
http://forum.planetpdf.com/wb/default.asp?action=9&read=58659&fid=5#160601