i am developing a utility that lists all users by age.
i want to be able to select all users between, for example, age 30 and 40.
i have come up with this so far:
$age_from = 30;
$age_from = 40;
// **************
// work out dob
// **************
$date_young = time() - (31556926 * $age_from);
$date_old = time() - (31556926 * $age_to);
// **************
// compose query
// **************
$match_finder_query = @mysql_query('SELECT * FROM users where dob BETWEEN \'' . date('Y-m-d', $date_old) . '\' AND \'' . date('Y-m-d', $date_young) . '\'', $database->connection) or die ('<b>MySQL Error:</b> ' . mysql_error());
while ($match_finder_result = mysql_fetch_assoc($match_finder_query)) {
echo $match_finder_result['username'] . "<br>\n";
}
all works fine with users under 30 years of age, however all users older than that are listed under the around 30 years old category.
it seems the unix epoch is playing havoc with my script.
anyone know how i can make this compatible with users older than 30?!
i have checked out the mysql manual (in the hope i can interate it all into 1 query) which doesnt seem to be very helpful...
whats the best way round this?
never really played with dates earlier than 1970.
thanks!