我创建了一个员工数据库,其中包含 varchar 格式 (31-12-2016) 或 d-m-Y 的出生日期。我想找到58岁及以上的员工。我使用此查询:
$age=mysql_db_query($db,"select * from employees where round(datediff(str_to_date(birth_day,'%d-%m-%Y'), curent_date())/365) > 58",@$koneksi);
$birth = mysql_num_rows($birth);
使用上述查询不显示任何内容。查询有什么问题?
提前感谢。
使用 abs()
将给出一个数字的绝对值。您的查询返回负值,因此您没有获得正确的记录。
尝试使用以下查询:
select *
from employees
where abs(round(datediff(str_to_date(birth_day,'%d-%m-%Y'), current_date())/365)) > 58"
你也用curent_date
代替了current_date()