Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to return results for an age range in sql?

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have a query i'm running, for people who are between 18 - 24 years old.

here's what i have:
Code:
$sth = $dbh->prepare("select * from dbtable where (((TODAYSDATE - uDOB) > 18)&&((TODAYSDATE - uDOB) < 25))");

where TODAYSDATE is a mysql function, and uDOB is my field that stores a the date of birth as YYYY/MM/DD.

any ideas?

- g
 
are you asking how to get the data out of the dbi module or if the SQL is correct?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
You should ask this question in the MySQL forum. You can use DEFINE for SELECT statment to check the STMT it's self. Also, I'll have to confirm but the date format in MySQL is YYYY-MM-DD vs xxxx/yy/zz; I've never trying mixing the two.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top