Full Version: Birthday Query
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
ashams
Please help me with a query.I have a table Members with feilds Name, Gender,DateofBirth .
I want to figure out which Members had birthdays that fell within a particular date range. The start date and end date will have values from the current year.
Bemmy
You could have a form with 2 unbound text boxes - DateFrom and DateTo (short date format). In the criteria grid of your query for the DateOfBirth field put - Between [Forms].[YourFormName].[DateFrom] And [Forms].[YourFormName].[DateTo]
You will then be able to print the query results in a report or display them on a form (you will have to requery the form when you change the date values).

Hope this helps.
ashams
Thanx for your response ,but this is not what i wanted.I have a similar form like u described .The start date and end date will be dates from the current year.But the date of brith can be from any year. For example, if I give the Fromdate as 5/Mar/2005 and ToDate as 11/May2005 the query should list all the people who celebrate their birthday in this range of date.I need to know how should i write the query to get the records.
truittb
Welcome to Utter Access.

Change the DOB to whatever you date of birth field is. The best way to pass the criteria to the query would be from a form. This is using hard coded dates. You can modify it as needed.

Where Month(DOB) = 3 and Day(DOB) Between 5 and 11
ashams
Could you be a litte more elaoborate. With the SQl statemnet in your post it will return only people with birthday falls in 5th March and 11th March.What I needed is a complete queryto list al the members having birthday in the given date range.the dates can fall in 2 different years also,
The table structure is
Member
Name Text
DOB Date

I need to know how to write the SQL statement that is the Select statement to list all the people who have Birthday in the given range of dates. That's we are not considering the year part in DOB. only the day and month parts of DOB.
For eg. The dates can be 25/12/04 to 3/1/05 or 3/1/05 to 17/1/05 or 18/1/05 to 3/2/05 and similar dates.
these FromDate and ToDate can be parameters in the selct statement.
truittb
Just change the month to a between.

Where Month(DOB) Between 2 and 6 and Day(DOB) Between 1 and 12
robandlorie
I had a problem if the date range crossed into the next year so I wrote a small Function I think might work and give you what you want. I attached a sample DB with it in it. Maybe this will help get you started anyway.


Have a wonderful day frown.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.