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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to have a query that changes Date of Birth to Age 2

Status
Not open for further replies.

CrimsonLily

Technical User
Feb 3, 2003
19
0
0
US
Ok, I've got a database that lists people by date of birth. And for a project that I'm doing I need the actual age in years.

Is there a query that will calculate a date of birth into an age in years??

Please help, I don't even know where to begin.

Thanks!!!

CrimsonLily
 
Ok :) Thanks again Rudy & Coco, for all your help.

I appreciate it greatly!!!

CrimsonLily
 
sorry i missed this, i had to go out

coco, this --

+ iif(year(date()) - year(DOB) < 0,100,0)

is pretty neat

 
I'll start by saying that I like the SQL solution provided by Rudy very much.

This function does the same thing for the lazy developers. Or use it in complex queries that might become too complex:

Function dnAgeYears(StartDate, Optional EndDate)
'=========================================================
'Daniel Vlas, June 10, 1999
'=========================================================

'==========================================================
'The function calculates the FULL years elapsed between two dates.
'It can be used to calculate the age of a person, instead of
'DateDiff function
'DatDiff will return 1 if:
'StartDate is Dec 31, 2000 and EndDate is Jan 01, 2001
'Nice, isn't it-especially when you are 1 day old but you want to look older :)
'===========================================================
On Error GoTo ErrHandler
If IsMissing(EndDate) Then EndDate = Date

If DateValue(Format(StartDate, &quot;dd mmmm&quot; & &quot;, &quot; & Year(EndDate))) > EndDate Then
dnAgeYears = Year(EndDate) - Year(StartDate) - 1
Else
dnAgeYears = Year(EndDate) - Year(StartDate)
End If
ExitHere:
Exit Function
ErrHandler:

'What can be wrong? Bad dates as arguments...
dnAgeYears = &quot;#DatesError&quot;
Resume ExitHere
End Function

HTH



[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top