Calculating age in years from dates

G

Guest

In Access, is there some way I can use a Birth Date field and the current
date to calculate age in years? Are there Expressions that will allow this to
be done in the Criteria row of a query? Can the current date be read directly
from the computer?
Thanks
 
G

Guest

The Date() will return the current date from the Computer
To get the age you can use the DateDiff Function
datediff("yyyy",DateField,date())

To use it in a query
Select TableName.* , datediff("yyyy",DateField,date()) as AgeField From
TableName

To add a criteria by age, for example all ages that are greater then 20 years:
Select TableName.* , datediff("yyyy",DateField,date()) as AgeField From
TableName Where datediff("yyyy",DateField,date()) > 20
 
D

Dirk Goldgar

Ofer said:
The Date() will return the current date from the Computer
To get the age you can use the DateDiff Function
datediff("yyyy",DateField,date())

Actually, no -- you can't. DateDiff may be off by as much as 364 days
(365, if this is a leap year!). As far as DateDiff is concerned, the
difference between #12/31/2005# and #1/1/2006# is 1 year. That's
because DateDiff counts interval *boundaries* between the two dates.
See the link I posted for various methods to calculate age accurately.
 
G

Guest

Great info. Thanks

Ofer said:
The Date() will return the current date from the Computer
To get the age you can use the DateDiff Function
datediff("yyyy",DateField,date())

To use it in a query
Select TableName.* , datediff("yyyy",DateField,date()) as AgeField From
TableName

To add a criteria by age, for example all ages that are greater then 20 years:
Select TableName.* , datediff("yyyy",DateField,date()) as AgeField From
TableName Where datediff("yyyy",DateField,date()) > 20

--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck
 

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