4 Replies Latest reply on Mar 19, 2012 11:51 AM by yourspoon

# calculate the age

Hello,

I need to know the age of a person in years, month and days and I already found this algorithm:

ElapsedYears (calculation, number result) =
Year ( Get ( CurrentDate ) ) - Year ( Birthdate ) - If ( Get ( CurrentDate ) < Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ); 1 ; 0 )

ElapsedMonths (calculation, number result) =
Mod ( Month ( Get ( CurrentDate ) ) - Month ( Birthdate ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Birthdate ) ; 1 ; 0 ) ; 12 )

ElapsedDays (calculation, number result) =
Day ( Get ( CurrentDate ) ) - Day ( Birthdate ) + If ( Day ( Get ( CurrentDate ) ) ≥ Day ( Birthdate ) ; 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( Birthdate ) ; Day ( Birthdate ) ; Day ( Get ( CurrentDate )- Day ( Get ( CurrentDate ) ) ) ) )

Since I do not need the function "CurrentDate" I changed it to this:

(note: I changend Get ( CurrentDate ) to ( Datum_Verlauf ) and Birthdate to Patient::GebDatum)

ElapsedYears (calculation, number result)=

Year ( Datum_Verlauf ) - Year ( Patient::GebDatum ) - If ( Datum_Verlauf < Date ( Month ( Patient::GebDatum ) ; Day ( Patient::GebDatum ) ; Year ( Datum_Verlauf ) ); 1 ; 0 )

ElapsedMonths (calculation, number result) =

Mod ( Month ( Datum_Verlauf ) - Month ( Patient::GebDatum ) + 12 - If ( Day ( Datum_Verlauf ) < Day ( Patient::GebDatum ) ; 1 ; 0 ) ; 12 )

ElapsedDays (calculation, number result) =

Day ( Datum_Verlauf ) - Day ( Patient::GebDatum ) + If ( Day ( Datum_Verlauf ) ≥ Day ( Patient::GebDatum ) ; 0 ; If ( Day ( Datum_Verlauf ) - Day ( Datum_Verlauf ) ) < Day ( Patient::GebDatum ) ; Day ( Patient::GebDatum ) ; Day ( Datum_Verlauf ) - Day( Datum_Verlauf ) ) )

Now it says, that there is no function "ElapsedDays"...

I'm not familiar with this type of script and I actually tought that the function "ElapsedDays" would be defined by "ElapsedYears (calculation, number result) = ", but obviously it's not. Can you please tell me what's wrong with it? =)

• ###### 2. Re: calculate the age

thank you! So I take it there actually is no good solution for this problem? Every suggested algorithm is somehow not working right...   Except for the one with the three seperate fields for years, months and days, which still doesn not fit for me.

• ###### 3. Re: calculate the age

yourspoon wrote:

Every suggested algorithm is somehow not working right...

Every suggested algorithm is somehow working right... It all depends on how you define "right" - and that's not a calculation problem.

IMHO, for medical purposes one should calculate the age in months as the number of average months that have elapsed since birth.

• ###### 4. Re: calculate the age

Yes, you are right, thank you for your help =)