如何从MySQL中的D.O.B字段获取年龄? [英] How to get an age from a D.O.B field in MySQL?
本文介绍了如何从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
希望这有助于您
这篇关于如何从MySQL中的D.O.B字段获取年龄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文