How to use formula calculate age using 2 date fields?

Hello,

My clients want to calculate age using two dates field. Date1: @Today, date2: BirthDate.

if the age is 1-12 month, display month, otherwise display year.

For example1: Today is 14/05/2008, BirthDate is 14/12/2007, then display 5 month.

   example 2: Today is 14/05/2008, BirthDate is 14/01/2001, then display 7 year.

I don’t know how to use formula to get it.

Help please.

Many thanks in advance.

Linda

Subject: RE: How to use formula calculate age using 2 date fields?

days := @Day(@Today) - @Day(bd);months := @Month(@Today) - @Month(bd) - @If(days < 0; 1; 0);

yrs := @Year(@Today) - @Year(bd) - @If(months < 0; 1; 0);

@If(yrs > 0; @Text(yrs) + " years"; @Text(months) + " months");

Subject: RE: How to use formula calculate age using 2 date fields?

Thank you very much Andre !!!

linda

Subject: I think the formulas needs modification

Andre’s formula didn’t work correctly for me. Could have been my fault. If @Today is 5/11/2010 and the BirthDate is 6/12/2010 if was getting a negative number of months old.

Here is the formula I used. I also needed to calculate the person’s age if they had deceased (as of the day they died). I am still not sure if this formula is “perfect”.

tod := @If(DeceasedDate!= “”; DeceasedDate; @Today);

bd := BIRTHDATE;

days := @Day(tod) - @Day(bd);

months := @Month(tod) - @Month(bd) - @If(days < 0; 1; 0);

m_dif := @Month(tod) - @Month(bd) - @If(days < 0; 1; 0);

m_tmp := @If(m_dif < 0; m_dif + 12; m_dif);

yrs := @Year(tod) - @Year(bd) - @If(months < 0; 1; 0);

@If(yrs > 0; @Text(yrs) + " years"; @Text(m_tmp) + " months")