Automatically calculating age

E

Emsytig

I've created a database and want to calculate a person's age from their date
of birth. I've done this in Forms using an expression but want to know if
there's a way to display this in the table so that it appears in queries?
Thanks!
 
S

scubadiver

Don't understand. If you can do it in a form then you can bind the age to a
field so it does get stored in a table!
 
F

fredg

I've created a database and want to calculate a person's age from their date
of birth. I've done this in Forms using an expression but want to know if
there's a way to display this in the table so that it appears in queries?
Thanks!

Why would you want th save the calculated Age in a table? It's sure
to be incorrect within 1 year.
Any time you need to see the Age, re-calculate it.

In a query you could use:

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

Emsytig

Thanks! May be being Dim but it doesn't seem to be working! I've set the
expression up in the form but it still appears as 'zero' in the table. Is
there something i'm doing wrong?
 
D

Dale Fye

You should NOT store the age in a table, since ages change (daily). If you
need an age, and you don't just want to display it in a report, create a
query that computes the age on the fly. That way, it will always be
up-to-the-minute.

Age: Datediff("yyyy", [DOB], Date()) _
+ (Format(date(), "mmdd") < Format([DOB], "mmdd"))

HTH
Dale
 
E

Emsytig

Surely if the calculation was between date of birth and current date it
should automatically update and won't be out of date? If I currently run a
query on my database and include the 'age' field it maintains a 'zero' value.
If I can get the field to display the person's current age (as it does on
the form) it should automatically appear in a query??!

fredg said:
I've created a database and want to calculate a person's age from their date
of birth. I've done this in Forms using an expression but want to know if
there's a way to display this in the table so that it appears in queries?
Thanks!

Why would you want th save the calculated Age in a table? It's sure
to be incorrect within 1 year.
Any time you need to see the Age, re-calculate it.

In a query you could use:

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

Emsytig

ok Thanks

Dale Fye said:
You should NOT store the age in a table, since ages change (daily). If you
need an age, and you don't just want to display it in a report, create a
query that computes the age on the fly. That way, it will always be
up-to-the-minute.

Age: Datediff("yyyy", [DOB], Date()) _
+ (Format(date(), "mmdd") < Format([DOB], "mmdd"))

HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.


Emsytig said:
I've created a database and want to calculate a person's age from their date
of birth. I've done this in Forms using an expression but want to know if
there's a way to display this in the table so that it appears in queries?
Thanks!
 

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