[EMAIL PROTECTED] wrote on 01/16/2007 07:36:53 PM:

> Okay, to be truly accurate - divide by 365.25.  (3 * 365) + 366 = 1461
> total days in a four year span including a leap year.  1461 / 4 =
> 365.25.

Actually, this isn't 100% accurate.  There are quite a few dates for which
this will generate an age that is off by one year.  I created a
demonstration program a long time ago to prove this, because we had a
program that was using this logic.  It never seemed quite right to me, and
it is right *almost* every time.  Calculating ages as of January 16, 2007
for all dates in the last ten years will show incorrect ages for January 16
of the following years: 1997, 1998, 2001, 2002, 2005, and 2006.  For
example, January 16, 2006 shows as zero years old (365/365.25 is less than
1).

My preferred method of calculating age is to extract the month, day, and
year of both dates and calculate the age as the difference between the
years.  Then, if the target MMYY is less than the birth MMYY, subtract one
from the age.  In other words, pretty much the way you would do it in your
head - or at least the way I do it in my head. ;-)  This also handles all
leap-year rules, including those funky 100- and 400-year ones, which are
not accommodated by simply dividing by 365.25.

Tim Snyder
Consulting I/T Specialist
U2 Consulting
North American Lab Services
IBM Software Group
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to