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

How to calculate a Member's Age using a query

Status
Not open for further replies.

mouk2007

Programmer
Jul 15, 2008
11
GB
I have a table of the date of birth of my members in my DVD rental shop and I also have a table for the current date. I wish to calculate the age of my members. Could anyone please let me know the code that I must use in the query to do this.

Many Thanks
 
why would you need a table for the current date? you can get that in a query:

Code:
SELECT BIRTH_DATE, (Now()-[BIRTH_DATE])/365.25 AS AGE FROM TableName

Leslie

Have you met Hardy Heron?
 
Thanks for the reply. I inserted the code you provided but I got a Syntax Error. Here is the SQL for my query:

SELECT Member.MemberNumber, Member.MemberDateOfBirth
FROM Member;
 
that query gave you a Syntax error? Is MemberDateOfBirth really a Date/Time field?

Code:
SELECT MemberNumber, MemberDateOfBirth, (Now() - MemberDateOfBirth)/365.25 As Age
FROM Member;

Leslie

Have you met Hardy Heron?
 
GREAT! Thanks a lot. This code works however it shows the age with lots of decimal places, e.g 25.565434123. Could you please let me know how I could get rid of the decimal places.
 
How are ya mouk2007 . . .

Be aware that the methods provided in this thread so far are inaccurate! Example:

Someone is born [blue]Dec 12, 1990[/blue]. On [blue]Jan 1, 2000[/blue] these methods will show an [blue]age of 10[/blue], when in fact (since Dec hasn't arrived yet) [purple]the true age is 9![/purple]

To circumvent this, is a select query that includes the BirthDay, add the following custom field ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]Age:DateDiff("yyyy", [[purple][B][I]BirthdayFieldName[/I][/B][/purple]], Now()) + Int(Format(Now(), "mmdd") < Format([[purple][B][I]BirthdayFieldName[/I][/B][/purple]], "mmdd"))[/blue]
Run the query to see the results.

[blue]Your Thoughts? . . .[/blue]

BTW: Welcome to [blue]Tek-Tips![/blue] [thumbsup2] Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and insite into [blue]etiquette[/blue] here in the forums. Again . . . Welcome to [blue]Tek-Tips![/blue] [thumbsup2] . . . Its [blue]worthy[/blue] reading!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Darn! [mad] Hit submitt too soon! . . .

With the code I provided, [blue]age changes on the exact birthdate![/blue] [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top