如何从 MySQL 的 D.O.B 字段中获取年龄?
我需要根据客户"的出生日期计算他们的年龄.
I need to calculate the age of a "customer" from their date of birth.
我尝试使用以下内容:
DATEDIFF(year, customer.dob, "2010-01-01");
DATEDIFF(year, customer.dob, "2010-01-01");
但它似乎不起作用.
有什么想法吗?我知道这会很简单!
Any ideas? I KNOW it is going to be something simple!
谢谢
推荐答案
几种方法:
select DATEDIFF(customer.dob, '2010-01-01') / 365.25 as age
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(customer.dob,'2010-01-01')), ‘%Y’)+0 AS age
希望对你有帮助
相关文章