By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Calculating a persons age using Access

P: n/a
I would like to have a persons age in my database using their date of birth.
Can anybody give me some sugestios how i can do this
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Age = DateDiff("yyyy", [DateOfBirth], Date()) - _
IIf(Format$(Date(), "mmdd") < Format$([DateOfBirth], "mmdd"), 1, 0)

You need that bit at the end in case they haven't had their birthday yet:
the DateDiff function is a little too literal (DateDiff("yyyy",
#12/'31/2003#, #1/1/2004#) will show a difference of 1 year)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Richard Gomez" <kr*****@bigpond.com> wrote in message
news:r8******************@news-server.bigpond.net.au...
I would like to have a persons age in my database using their date of birth. Can anybody give me some sugestios how i can do this

Nov 12 '05 #2

P: n/a
>I would like to have a persons age in my database using their date of birth.
Can anybody give me some sugestios how i can do this


Here's a nice little function I took from someone here in CDMA (probably Dev
Ashish but I unfortunately didn't save the credit for it). The only advantage
over Doug's solution is that it allows you to easily set the "as of" date. I
use it when I want "age at entry" or some such. Watch out for line wraps.

Jan

Function agecalc(DOB, Optional vDate)

'Returns the Age in years, for a person whose Date Of Birth is DOB.
'Age calculated as of vDate, or as of today if vDate is missing.

If Not IsDate(vDate) Then vDate = date
If IsDate(DOB) Then
agecalc = DateDiff("yyyy", DOB, vDate) + (DateSerial(year(vDate),
Month(DOB), day(DOB)) > vDate)
Else
agecalc = Null
End If

End Function
Jan Stempel
Stempel Consulting
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.