# Thread: Age in years & age in days (2003)

1. ## Age in years & age in days (2003)

Hi,

I have two fields of employee (date of birth field, hiring date) in my database. Now I need create two fields to calcalate the age in years at hiring date & age in days at hiring date (coded only when the age in years is less than 1).

So what's the best way to get the data in those new two fields?

Thanks in advance.

Regards,

2. ## Re: Age in years & age in days (2003)

You could use this custom VBA function:

Function Age(Bdate, DateToday) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday
Age = Year(DateToday) - Year(Bdate)
If Month(DateToday) < Month(Bdate) Or _
(Month(DateToday) = Month(Bdate) And _
Day(DateToday) < Day(Bdate)) Then
Age = Age - 1
End If
End Function

You can use it in a query:

AgeYears: Age([Date of Birth],[Hiring Date])

How could someone's age be less than 1? Are you hiring newborn babies?

3. ## Re: Age in years & age in days (2003)

Thanks, Hans.

The age in years is working, but not age in days. What should I put in Age in days field in a query? If the age in years is great than 1, then the age in days field is blank. If the age in years is less than 1, then the age in days field will show the days between Bdate and DateToday.

Thanks again.

Regards,

4. ## Re: Age in years & age in days (2003)

AgeDays: IIf([AgeYears]<1,[Hiring Date]-[Date of Birth],Null)

5. ## Re: Age in years & age in days (2003)

Thank you, Hans.

#### Posting Permissions

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