如何从 MySQL 的 D.O.B 字段中获取年龄? [英] How to get an age from a D.O.B field in MySQL?

查看:22
本文介绍了如何从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆