8 Replies Latest reply on Jun 24, 2013 11:42 PM by Vaughan

# How to display age in 2 digit number

I need help with calculating the age of a student in our database, based on a calculation from a date of birth field. Ex. Jane Doe 12/15/97 in "DOB" field would also result in Jane is 15 in the "age" field.

• ###### 1. Re: How to display age in 2 digit number

Let(

[

today = Get ( CurrentDate );

dob = DateOfBirth

];

If(

today > dob and IsEmpty(dob) ≠ 1;

Year(today) - Year(dob) - If(today < Date(Month(dob);

Day(dob);  Year(today));  1;  0);

"")

)

--> Remember to define calc as a number and we do not evaluate if all referenced fields are empty (tickbox)

--->There might be more savvy ways, we have had this calc in our db for years!

• ###### 2. Re: How to display age in 2 digit number

... and make the calculation unstored.

1 of 1 people found this helpful
• ###### 3. Re: How to display age in 2 digit number

Thanks much! Also found this in case you need an alternative.

GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( Student Birth Date ) - If ( Get ( CurrentDate ) <  Date ( Month ( Student Birth Date ) ; Day ( Student Birth Date ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) )

• ###### 4. Re: How to display age in 2 digit number

There's always the even simpler:

Int((Get(CurrentDate) - Date of Birth) / 365.25)

Marc

• ###### 5. Re: How to display age in 2 digit number

If you really need two digits you can use the RIGHT function:

`Right ( "00" &   Year (   get ( currentDate ) - Date of Birth   )   ; 2 )`

This will result in age: 01

Richard

• ###### 6. Re: How to display age in 2 digit number

Hi Marc,

I'm afraid this calculation will not always give the correct answer on someone's birthday. E.g. with your calculation a DOB = 1/1/2001  will result in age=10, not 11, if today is 1/1/2012.

The reason is: (birth) dates and ages are discrete values, not fractions. Dividing by 365.25 doesn't  account correctly for leap years. A year is either a leap year, or it isn't. Years on the calendar do not have 365.25 days. Of course, astronomically they do (approximately), but  that's not practical for earthbound use. It's why we have leap years in the first place.

The leap day itself is  a discrete, 'sudden' shift.

regards, Peter

• ###### 7. Re: How to display age in 2 digit number

But what about the centarians out there!?

• ###### 8. Re: How to display age in 2 digit number

Hail Caesar! Oh, centarian, not centaurian.

It's interesting how challenges like these illustrate the assumptions we make -- such as 2 digits for the age, and a year being 365.25 days.