Calculate AGE

G

Guest

i need help to calculate age by using dob.what kind of field do i need for
the dob and what kind of format?

thanks irit
 
D

Douglas J. Steele

DOB should be a date field.

Age (in years) is calculated as

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

DateDiff calculates how many "year crossings" occur between the two dates:
it'll say that there's 1 year between 31 Dec of one year and 1 Jan of the
next year, despite the fact that it's really only 1 day. That's why you
subtract 1 from the calculation if the birthday hasn't taken place yet this
year.

If you want finer granularity than years, (say 28 year, 7 months and 2
days), see http://www.accessmvp.com/DJSteele/Diff2Dates.html
 
G

Guest

I used itlike this but it is not working,I change the format in the ageyearly
to a date formal(mm/dd/yyyy)
AgeYearly = DateDiff("yyyy", [DOB], Date) - _
IIf(Format([DOB], "mmdd") < Format(Date, "mmdd"), 1, 0)
still it is not working
thanks Irit


Douglas J. Steele said:
DOB should be a date field.

Age (in years) is calculated as

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

DateDiff calculates how many "year crossings" occur between the two dates:
it'll say that there's 1 year between 31 Dec of one year and 1 Jan of the
next year, despite the fact that it's really only 1 day. That's why you
subtract 1 from the calculation if the birthday hasn't taken place yet this
year.

If you want finer granularity than years, (say 28 year, 7 months and 2
days), see http://www.accessmvp.com/DJSteele/Diff2Dates.html

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Imarko said:
i need help to calculate age by using dob.what kind of field do i need for
the dob and what kind of format?

thanks irit
 
D

Douglas J. Steele

What didn't work about it?

I noticed in another response that you said
http://www.mvps.org/access/datetime/date0001.htm worked for you. What I gave
you is essentially the same as the first response on that page.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Imarko said:
I used itlike this but it is not working,I change the format in the
ageyearly
to a date formal(mm/dd/yyyy)
AgeYearly = DateDiff("yyyy", [DOB], Date) - _
IIf(Format([DOB], "mmdd") < Format(Date, "mmdd"), 1, 0)
still it is not working
thanks Irit


Douglas J. Steele said:
DOB should be a date field.

Age (in years) is calculated as

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

DateDiff calculates how many "year crossings" occur between the two
dates:
it'll say that there's 1 year between 31 Dec of one year and 1 Jan of the
next year, despite the fact that it's really only 1 day. That's why you
subtract 1 from the calculation if the birthday hasn't taken place yet
this
year.

If you want finer granularity than years, (say 28 year, 7 months and 2
days), see http://www.accessmvp.com/DJSteele/Diff2Dates.html

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Imarko said:
i need help to calculate age by using dob.what kind of field do i need
for
the dob and what kind of format?

thanks irit
 

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

Similar Threads

Sorting dates by month 6
Calculate Age 3
What event to use in a field property on a from 1
Creating a calculated field using dates in a form 3
Calculateing age 1
date calculations 5
AgeGroup 6
Age Calculation 8

Top