Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Age from Birth date

Status
Not open for further replies.

Snookless

Technical User
Mar 17, 2003
34
BR
Hello all,
Any help on how to calculate age from a birth date?
Thank you
 
A little more complicated that you might think because of leap year:

if month({TABLE.BIRTHDATE})=2 and day({TABLE.BIRTHDATE})=29 and
day(date(year(CurrentDate),3,1)-1)=28
then
if date(year(CurrentDate),month({TABLE.BIRTHDATE}),day({TABLE.BIRTHDATE})- 1) > CurrentDate
then year(CurrentDate)-year({TABLE.BIRTHDATE})-1
else year(CurrentDate)-year({TABLE.BIRTHDATE})
else
if date(year(CurrentDate),month({TABLE.BIRTHDATE}),day({TABLE.BIRTHDATE})) > CurrentDate
then year(CurrentDate)-year({TABLE.BIRTHDATE})-1
else year(CurrentDate)-year({TABLE.BIRTHDATE})

-k
 
In Crystal 8.5, use something like

DateDiff ("yyyy", {birth.date}, currentdate)

Irritatingly, this will work on calendar values, which means it will be wrong for people whose birthday is after the current date. Use DatePart to check for such conditions and adjust.

You'll also need to do an isnull({birth.date}) check for people whose birthdate you do not know.

Madawc Williams
East Anglia
Great Britain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top