Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asptoday_discuss thread: Age Range Queries


Message #1 by "Jeremy Palmer" <medicalendar@h...> on Tue, 25 Jun 2002 18:00:15
I have a form that allows users to search by a persons age.  

For example:

I am looking for somebody between the age of 18 and 25.  

The persons birthdate is stored in the database as a date value 
(08/31/1978).  Could somebody show me a sample SQL Query that could 
retrieve an age range from a database with this type of information?

Thanks!

Jeremy
Message #2 by "Sheets, Kim" <kim.sheets@e...> on Tue, 25 Jun 2002 12:06:43 -0500
Here are a couple of ways doing it.

select * from table
 where birthdate between 08/31/1978 and 08/31/1985

or 

select * from table
 where birthdate >= 08/31/1978 and birthdate <= 08/31/1985

good luck
KC Sheets

-----Original Message-----
To: ASPToday Discuss
Subject: [asptoday_discuss] Age Range Queries

I have a form that allows users to search by a persons age.  

For example:

I am looking for somebody between the age of 18 and 25.  

The persons birthdate is stored in the database as a date value 
(08/31/1978).  Could somebody show me a sample SQL Query that could 
retrieve an age range from a database with this type of information?

Thanks!

Jeremy
Message #3 by "Jason Salas" <jason@k...> on Wed, 26 Jun 2002 07:13:53 +1000
Hi Jeremy,

I'm going to assume that not all the values are 8/31/1978.  So, you'd first
need to evaluate the date/time value, to see if it is indeed 18 to 25 years
relative to the current date.  This would require you to use a sliding
variable amount for 25...say for someone who was born on 12/31/1978, and
hasn't turned 25 just yet. You could try something like this:

Dim day, month
day = Day(Date())
month = Month(Date())

"SELECT * FROM Table WHERE Date BETWEEN #1/31/1985# AND #" & month & "/" &
day & "/1978#"

Have fun!
Jason

---------------------------------------------------
Jason Salas, MBA, MCP
Web Development Manager
Pacific Telestations, Inc. (dba, "KUAM")
URL: http://www.kuam.com
President, .NET User Group of Guam
URL: http://www.guam-asp.net
Mailto: jason@k...


----- Original Message -----
From: "Jeremy Palmer" <medicalendar@h...>
To: "ASPToday Discuss" <asptoday_discuss@p...>
Sent: Tuesday, June 25, 2002 6:00 PM
Subject: [asptoday_discuss] Age Range Queries


> I have a form that allows users to search by a persons age.
>
> For example:
>
> I am looking for somebody between the age of 18 and 25.
>
> The persons birthdate is stored in the database as a date value
> (08/31/1978).  Could somebody show me a sample SQL Query that could
> retrieve an age range from a database with this type of information?
>
> Thanks!
>
> Jeremy
>


  Return to Index