• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

convert birthdate to age

I have two fields in my access form  AgeG and Agel that I need added to the query below. I need to find the age of the person from the dob field then get all records that fall in that age group between ageG and AgeL.  What is the best way to handle this?
SELECT tblDemo.clinic_code, tblDemo.chart_number, tblDemo.last_name AS LastName, tblDemo.first_name AS Firstname, tblDemo.address1 AS Address1, tblDemo.address2 AS Address2, tblDemo.city AS City, tblDemo.state AS State, tblDemo.zip AS Zip, tblDemo.phone1 AS Phone1, tblDemo.phone2 AS Phone2, tblDemo.sex, tblDemo.dob
FROM tblDemo LEFT JOIN Qry_ListPatientReceiveService2 ON (tblDemo.chart_number = Qry_ListPatientReceiveService2.chart_number) AND (tblDemo.clinic_code = Qry_ListPatientReceiveService2.clinic_code)
WHERE (((Qry_ListPatientReceiveService2.chart_number) Is Null) AND ((Activeclinic2([tblDemo]![clinic_code]))=True) AND ((Activeperiod2([tblDemo].[start_date],Nz([tblDemo].[end_date],Date())))=True)) AND ((tblDemo.sex)=[Forms]![frmMain2]![txttemp]);

Open in new window

1 Solution
You can use the DateDiff function: http://www.techonthenet.com/access/functions/date/datediff.php
When you do your select it will look something like this.
WHERE DateDiff ( y, DateOfBirth, NOW()) BETWEEN AgeG AND AgeI

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now