Calculate AGE

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top