Calculate age from Date of Birth

  • Thread starter Thread starter Alan F
  • Start date Start date
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
 
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


.
 
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


.
 
Alan,

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