View Single Post
07-31-2008, 09:09 PM
#2
infinivert is offline infinivert
infinivert's Avatar
Status: Junior Member
Join date: Jul 2008
Location: Abilene TX
Expertise: Design, PHP, JS, HTML5, CSS3
Software:
 
Posts: 37
iTrader: 0 / 0%
 

infinivert is on a distinguished road

Send a message via AIM to infinivert

  Old

Sure, it just requires a slightly more complicated SQL statement that converts the date or datetime field to a Unix timestamp. I would probably do something like this:
PHP Code:
$age 20 // change this variable to get different ages

$age_sql "SELECT * FROM tblTableName WHERE UNIX_TIMESTAMP(fldBirthDate) >= UNIX_TIMESTAMP(NOW())-" $age 31556926 " AND UNIX_TIMESTAMP(fldBirthDate) < UNIX_TIMESTAMP(NOW())-" . ($age 1) * 31556926 ";"
...where tblTableName is the table and fldBirthDate is the field containing your birthdates.

A Unix timestamp is the number of seconds since Jan. 1, 1970. 31556926 is the number of seconds in 1 year (365.24 days).

I haven't tested this explicitly, so no guarantees, but I think it gets the general idea across. And I'm sure there may be a more eloquent way to do this, so if anybody knows one, please share!