-
慕无忌1623718
如果值存储为DATETIME数据类型:SELECT YEAR(CURRENT_TIMESTAMP) - YEAR(dob) - (RIGHT(CURRENT_TIMESTAMP, 5) < RIGHT(dob, 5)) as age FROM YOUR_TABLE考虑闰年时不太精确:SELECT DATEDIFF(CURRENT_DATE, STR_TO_DATE(t.birthday, '%d-%m-%Y'))/365 AS ageInYears FROM YOUR_TABLE t
-
明月笑刀无情
你可以使用TIMESTAMPDIFF(unit, datetime_expr1, datetime_expr2)功能:SELECT TIMESTAMPDIFF(YEAR, '1970-02-01', CURDATE()) AS age
-
达令说
select *,year(curdate())-year(dob) - (right(curdate(),5) < right(dob,5)) as age from your_table通过这种方式,您可以考虑出生的月份和日期,以便更准确地计算年龄。