这就是为什么将所有日期保存为时间戳而不是实际日期的原因,因为在两个数值之间找到范围要容易得多。
您可以尝试使用当前设置来查找18-25之间的所有人:
$age1 = 18; //These two would be external inputs from whatever search form
$age2 = 25;
$date1 = date("Y.M.d",time() - ($age1 * 365 * 24 * 60 * 60));//Subtract the number of seconds equivalent to X years from current timestamp, Convert timestamps to appropriate dates for the format in the DB
$date2 = date("Y.M.d",time() - ($age2 * 365 * 24 * 60 * 60));//Strtotime("18 years ago") might work, not sure
$sql = mysql_query("SELECT * FROM `users` WHERE `birthdate` >= '$date1' AND `birthdate` <= '$date2'");
$result = mysql_fetch_assoc($sql);