3 Replies Latest reply on Aug 7, 2009 3:35 PM by comment_1

# Calculating age using date collected and DOB (Date of Birth)

### Title

Calculating age using date collected and DOB (Date of Birth)

### Post

I found this calculation from FM;

GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( Birthdate ) - If ( Get ( CurrentDate ) <  Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( Birthdate ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Birthdate ) ; 1 ; 0 ) ; 12 ) ) & " Months, "  and it works fine when I substitute my d'bases fields "Date Collected" for "Get (CurrentDate" and "DOB" for "Birthdate" ....but I really don't want to show "0" years when a person is <1 yr. I would like to show only months. The other option would be to show"<1" instead of months.

I've fiddled with the calc and come up to a road block.

Greg

• ###### 1. Re: Calculating age using date collected and DOB (Date of Birth)

Try something like:

`Let ( [m = 12 * ( Year ( DateCollected ) - Year ( DOB ) ) + Month ( DateCollected ) - Month ( DOB ) - ( Day ( DateCollected ) < Day ( DOB ) )] ;Case ( m ≥ 12 ; Div ( m ; 12 ) & " Years, " ) & Mod ( m ; 12 ) & " Months") ---Note that this assumes a person  becomes a month older on the same day-in-month as their DOB or when the month ends - whichever happens first.`
• ###### 2. Re: Calculating age using date collected and DOB (Date of Birth)

OK that works great! But now that i see the result of the calc I think that if an individual is <1 a result in months would be OK...but if >1 just a result of years would do fine. Is there a way to adjust the calc to yield those results?

For example if DateofBirth is <1, result would be "X Months" or if age >1 then result would be "X years.

Thanks for the help. Your clearly more up to speed on this than I. I was rocking and rolling with FM until 7 came out. Now I've in the dark on alot of things that used to be easy for me. I guess it's age!!

Happy Hour

• ###### 3. Re: Calculating age using date collected and DOB (Date of Birth)

Just change the result line to:

Case ( m ≥ 12 ; Div ( m ; 12 ) & " Years" ; m & " Months" )