For age in whole years, this is pretty easy, just subtract the DOB year
from the current year to get age, but if the current month and day are
earlier in the year than the date of birth month and day, subtract 1
from the age.

Suppose variable DOB holds the date of birth in internal format.  This
code will give you the age today:

      DOBX = OCONV(DOB,'D4/')
      DOB.YR = DOBX[7,4]
      DOB.DA = DOBX[4,2]
      DOB.MO = DOBX[1,2]

      NOWX = OCONV(DATE(),'D4/')
      NOW.YR = NOWX[7,4]
      NOW.DA = NOWX[4,2]
      NOW.MO = NOWX[1,2]

      AGE = NOW.YR - DOB.YR
      * We will subtract 1 from age if the 'now' month & day is earlier
in the
      * year than the 'dob' month & day, otherwise not

      IF NOW.MO < DOB.MO THEN
         AGE = AGE - 1
      END ELSE
         IF NOW.MO = DOB.MO AND NOW.DA < DOB.DA THEN
            AGE = AGE - 1
         END
      END

      * The variable AGE now holds their age as of the current day.


This even works if the DOB is 02/29 in some year, assuming that 02/28 in
the current year is not a person's birthday, but 03/01 is considered to
be their birthday.

Harold Oaks
Sr. Programmer/Analyst
Clark County, WA


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dominion
Sent: Tuesday, January 16, 2007 3:12 PM
To: [email protected]
Subject: [U2] RE: [UV] Calculate age from date of birth

Needs to be in whole years, ie, age 40 at 6 April 2006 - must be exactly
correct as this is for pension calculations so can't get it wrong due to
a rounding discrepancy!


What units do you want it in?  Days?  Years and fractional parts of
years?
Years, months & days?

Larry Hiscock
Western Computer Services
 
--
View this message in context:
http://www.nabble.com/-UV--Calculate-age-from-date-of-birth-tf3023501.ht
ml#a8401316
Sent from the U2 - Users mailing list archive at Nabble.com.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to