Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate age

Status
Not open for further replies.

churdle

Programmer
Apr 2, 2000
7
US
from a date of birth field, how can i calculate a person's age on a particular day (not neccessarily today's date)?
 
Try this in a function:<br><br>Public Function fGetAge(BDate As Date) As Integer<br>fGetAge = DateDiff(&quot;yyyy&quot;, BDate, Date) + (Date &lt; DateSerial _<br>(Year(Date), Month(BDate), Day(BDate)))<br>End Function<br><br>HTH<br>RDH <p>Ricky Hicks<br><a href=mailto: rdhicks@mindspring.com> rdhicks@mindspring.com</a><br><a href= > </a><br>
 
I believe that if, as you said, you want this to work for any date, you'd modify it this way:<br><br>Function Age(BDate As Date, ChosenDate) As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;Age = DateDiff(&quot;yyyy&quot;, BDate, ChosenDate) +&nbsp;&nbsp;_<br>&nbsp;&nbsp;&nbsp;&nbsp;(ChosenDate &lt; DateSerial (Year(ChosenDate), Month(BDate), Day(BDate)))<br>End Function
 
Thank for catcing that Elizabeth, I think I was brain dead when I read the original post.<br><br>Thanks<br>RDH <p>Ricky Hicks<br><a href=mailto: rdhicks@mindspring.com> rdhicks@mindspring.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top