# Thread: Age Calculation

1. ## Age Calculation

I'm sure this has been asked many times before but if someone could help... What would the formula look like to calculate AGE from Today's Date and a Birthdate and have it return Years &amp; Months... i.e. 11 years 4 months old.

2. ## RE: Age Calculation

Years:
age(birthdate, date()) would give you the years

Months:
if(month(date()) - month(birthdate)"= 0, month(date()) - month(birthdate), month(date()) - month(birthdate) + 12)

Looks like a two step script to me. Don't know of a way to do it in a single statement.

-- tom

3. ## RE: Age Calculation

This is the calc that I use, there may be a better solution.

STR(INT((DATE()-DOB)/30.4167/12),2)+":"+STR(MOD(INT((DATE()-DOB)/30.4167),12),2)

Michael

4. ## RE: Age Calculation

I'll give it a try. Thanks Very Much!

Mike

5. ## RE: Age Calculation

Mike,

Here is a function that I got from Charles Hoens and with a slight change, it returns exactly what you want - even the years and months are singular when there is only one.

'Date Created: 21-Feb-2003 02:43:35 PM
'Last Updated: 24-Aug-2004 10:49:24 AM

FUNCTION ChildAge AS C (DOB AS D )
dim fyear1 as n
dim fyear2 as n
dim fmonth1 as n
dim fmonth2 as n
dim yearage as n
dim mosage as n
dim totmos as n
dim newyears as n
dim newmos as n
dim cyrs1 as c
dim cmos1 as c

fyear1=year(DOB)
fyear2=year(date())
fmonth1=month(DOB)
fmonth2=month(date())

yearage=(fyear2-fyear1)*12
mosage=fmonth2-fmonth1

totmos=yearage+mosage
newyears=int(totmos/12)
newmos=totmos-newyears*12

if newyears = 1
cyrs1 = "Year"
else
cyrs1 = "Years"
end if
if newmos = 1
cmos1 = "Month"
else
cmos1 = "Months"
end if

ChildAge=alltrim(str(newyears))+" "+cyrs1+", "+alltrim(str(newmos))+" "+cmos1

END FUNCTION

Dave

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•