• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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