Calculate Age

G

Guest

I have a form where I need to calculate the age.

I have a text box for the DOB and a text box for the Date. I inserted a
text box to calculate the age from the Date of the event. I need to know
what formula will work. I have tried the following -

=([Date]-[DOB])/365 and I get #Error

Thanks for any help.
 
R

Roger Carlson

There are acutally more than 365 days in a year and your calculation won't
take leap year into consideration. 'd use the DateDiff function:

=DateDiff("yyyy", [Date], [DOB])

However, your calculation shouldn't be causing an error. "Date" is a
reserved word in Access and it causes odd problems at the least opportune
times. You also might want to make sure your textbox name is not the same
as one of your fields.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
G

Guest

Per another post from someone asking the same thing a month or so ago, first
is a clip of my post then the corrected answer from John Vinson. Hope that
helps. =)
=DateDiff("yyyy", [DOB], [DOE])

the "yyyy" will calculate the time is years. "d" Days and so on. DOB would
be the name of your field for Date of Birth and I used DOE for the name of
your field for Date of Expiration.

That will be close... but not absolutely accurate, at least by the traditional
use of "age". DateDiff actually counts year (or day, or second, or...)
boundaries, not full years; so if [DOB] were 12/31/1875 and [DOE] were
1/1/1876 - just a day later - the age would be reported as one year. Or if
[DOB] were 1/1/1931 and [DOE] 12/29/1931 - almost a year - you'ld still get 0.

You can correct for this with an expression:

DateDiff("yyyy", [DOB], [DOE]) - IIF(Format([DOE], "mmdd") > Format([DOB],
"mmdd"), 1, 0)


John W. Vinson [MVP]


Denise said:
I have a form where I need to calculate the age.

I have a text box for the DOB and a text box for the Date. I inserted a
text box to calculate the age from the Date of the event. I need to know
what formula will work. I have tried the following -

=([Date]-[DOB])/365 and I get #Error

Thanks for any help.
 

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