calculating age

1. Junior Member
Join Date
Dec 1969
Posts
21

calculating age

Hello,<BR><BR>Does anyone have a simple way to calculate age? datediff(y.. won&#039;t work because it simply finds the difference in years and datediff(d../365 does not take into account leap years.<BR><BR>Any suggestions appreciated.<BR><BR>Thanks, Mike

2. Senior Member
Join Date
Dec 1969
Posts
5,104

Why doesn't datediff work?

The difference in years from your date of birth to today would be what you need, wouldn&#039;t it?<BR><BR>-Doug

3. Junior Member
Join Date
Dec 1969
Posts
21

RE: Why doesn't datediff work?

Hi Doug,<BR><BR>datediff(y, 3/1/1998, 2/1/2000) would return 2 because, strictly speaking the difference between 1998 and 2000 is 2 but on 2/1/2000, the age is actually 1 and won&#039;t be 2 until we reach 3/1/2000.<BR><BR>Mike

4. Senior Member
Join Date
Dec 1969
Posts
5,104

Why not check for that?

Dim dtDOB<BR> dtDOB = #3/1/1998#<BR>Dim iYears<BR> iYears = DateDiff("y", dtDOB, Date())<BR> If Date() &#062; dtDOB Then iYears = iYears - 1<BR><BR>-Doug

5. Junior Member
Join Date
Dec 1969
Posts
21

RE: Why not check for that?

Yes. That works. Thanks!<BR>public function age(dteBeg, dteEnd)<BR>dim yEnd, dteBegAlt, yDiff<BR>yEnd = year(dteEnd)<BR>yDiff=datediff("yyyy",dteBeg, dteEnd)<BR>dteBegAlt = dateserial(year(dteEnd),month(dteBeg),day(dteBeg)) <BR>if dteBegAlt&#060;=dteEnd then<BR> &#039;have passed bday in current year<BR> age = yDiff <BR>else<BR> &#039;have not reached next bday in current year<BR> age = yDiff -1<BR>end if<BR>end function%&#062;

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•