如何根据 mysql 中的出生日期计算年龄?
How to calculate age based on date of birth in mysql?
我的出生日期格式是:2017-Feb-15
当我使用以下查询时,它不起作用
select (year(current_date)-year(dob)) as age from user
或者如何将当前 2017-Feb-15 转换为 2017-02-15 格式
您可以使用 TIMESTAMPDIFF.
select TIMESTAMPDIFF(YEAR, str_to_date(dob, '%Y-%M-%d'), current_date) AS age
from user;
我的出生日期格式是:2017-Feb-15
当我使用以下查询时,它不起作用
select (year(current_date)-year(dob)) as age from user
或者如何将当前 2017-Feb-15 转换为 2017-02-15 格式
您可以使用 TIMESTAMPDIFF.
select TIMESTAMPDIFF(YEAR, str_to_date(dob, '%Y-%M-%d'), current_date) AS age
from user;