Calculate an age from a birthdate using a specific date in time

K

karen k-12

I have a table containing student birthdates (yyyymmdd). This information
was collected Spring 2007. I need to calculate the age of the student at
that time. Could you please help me create a calculated field for this table
that displays the age. Thanks.
 
J

John W. Vinson

On Wed, 5 Dec 2007 10:19:01 -0800, karen k-12 <karen
I have a table containing student birthdates (yyyymmdd).

What's the datatype of this field? Number? Text? Maybe even a Date/Time field
(which is what you want)?
This information
was collected Spring 2007. I need to calculate the age of the student at
that time. Could you please help me create a calculated field for this table
that displays the age. Thanks.

You cannot and should not store calculated fields in a Table.

If you have the birthdate in a Date/Time field, you can use a Query, or the
control source of a textbox in a Form or Report, to dynamically calculate the
age:

Age: DateDiff("yyyy", [Birthdate], Date()) - IIF(Format([Birthdate], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

If your field is a text field, you can use

CDate(Format([textbirthdate], "@@@@-@@-@@"))

in place of [birthdate] in the age expression - but you'ld do better to create
a date/time field and use an update query with the same CDate expression to
populate it.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top