inhibit rounding

E

Evelyn Ballantyne

In a birthday list I am calculating from the date of
birth to get the result "how old next birthday"

The date of birth is in the field called bday.
I am using this formulae on the form.

=(Now()-[bday])/365.25+1
How do I inhibit the rounding because it rounds up and in
some cases shows the wrong age.
Many thanks in anticipation
 
G

Graham Mandeno

Hi Evelyn

The method you are using to calculate age is not completely reliable. Here
is a function that will work every time:

Public Function AgeInYears( _
dtBirthDate As Variant, _
Optional dtAgeAt) As Variant
If IsDate(dtBirthDate) Then
If IsMissing(dtAgeAt) Then dtAgeAt = Date
AgeInYears = DateDiff("yyyy", dtBirthDate, dtAgeAt) _
+ (dtAgeAt < DateSerial(Year(dtAgeAt), _
Month(dtBirthDate), Day(dtBirthDate)))
End If
End Function

Paste the code above into a standard module, and you can then use the
formula:
=AgeInYears([bday])

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
E

Evelyn

Thank you so much Graham, I will try it now. - Evelyn
-----Original Message-----
Hi Evelyn

The method you are using to calculate age is not completely reliable. Here
is a function that will work every time:

Public Function AgeInYears( _
dtBirthDate As Variant, _
Optional dtAgeAt) As Variant
If IsDate(dtBirthDate) Then
If IsMissing(dtAgeAt) Then dtAgeAt = Date
AgeInYears = DateDiff("yyyy", dtBirthDate, dtAgeAt) _
+ (dtAgeAt < DateSerial(Year(dtAgeAt), _
Month(dtBirthDate), Day(dtBirthDate)))
End If
End Function

Paste the code above into a standard module, and you can then use the
formula:
=AgeInYears([bday])

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.

In a birthday list I am calculating from the date of
birth to get the result "how old next birthday"

The date of birth is in the field called bday.
I am using this formulae on the form.

=(Now()-[bday])/365.25+1
How do I inhibit the rounding because it rounds up and in
some cases shows the wrong age.
Many thanks in anticipation


.
 

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