Calculate age from Date of Birth

A

Alan F

What calculation would I use in a form to display a persons age if I already
have their Date of Birth.

Many thanks in advance
 
D

Douglas J. Steele

Except that that's going to be wrong if the person hasn't had his/her
birthday yet.

DateDiff("yyyy", #12/31/2003#, #1/1/2004#) returns 1 year, despite the fact
it's only 1 day.

To take this into account, use:

DateDiff("yyyy",[DateOfBirth],[Date]) - IIf(Format(Date, "mmdd") <
Format([DateOfBirth], "mmdd"), 1, 0)



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Art said:
Hello

DateDiff("yyyy",[DateOfBirth],[Date])
-----Original Message-----
What calculation would I use in a form to display a persons age if I already
have their Date of Birth.

Many thanks in advance


.
 
A

Alan F

Hi,

Have tried pasting the code behind a unbound text box called Age and I keep
getting an error, as I missing something. I put it on the on enter event on
the text box. When I paste in the paste is displayed in RED can you help.

Thanks, Alan


Douglas J. Steele said:
Except that that's going to be wrong if the person hasn't had his/her
birthday yet.

DateDiff("yyyy", #12/31/2003#, #1/1/2004#) returns 1 year, despite the fact
it's only 1 day.

To take this into account, use:

DateDiff("yyyy",[DateOfBirth],[Date]) - IIf(Format(Date, "mmdd") <
Format([DateOfBirth], "mmdd"), 1, 0)



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Art said:
Hello

DateDiff("yyyy",[DateOfBirth],[Date])
-----Original Message-----
What calculation would I use in a form to display a persons age if I already
have their Date of Birth.

Many thanks in advance


.
 
S

Steve Schapel

Alan,

Try putting it, preceded with a = sign, in the Control Source property
of the textbox.
 
A

Arvin Meyer

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