本文介绍了使用SQL从类型日期的生日字段获取年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL数据库中有一个表,其中包含 date 类型的字段。这里存储用户的生日。是否有一种纯SQL方式来从字段中选择年龄?
I have a table in a MySQL database with a field of the type date. Herein the birthday of a user is stored. Is there a pure SQL way to select the age in years from the field?
推荐答案尝试这样...
SELECT id, Name, DateofBirth, ((DATEDIFF(Cast((Select Now()) as Date), Cast(DateofBirth as Date)))/365) AS DiffDate from TABEL1编辑从Transact Charlie ...了解事实...
Edit Considereing Fact from Transact Charlie....
SELECT id, Name, DateofBirth, TIMESTAMPDIFF(Year, Cast(DateofBirth as Date), Cast((Select Now()) as Date)) AS DiffDate from TABEL1更多推荐
使用SQL从类型日期的生日字段获取年龄
发布评论