SQL查询【根据生日计算】
根据生日日期,获取当前年龄、年龄单位。
Select Case when DateDiff(Year, BirthDate, GetDate()) > 0 then DateDiff(Year, BirthDate, GetDate())
when DateDiff(Month, BirthDate, GetDate()) > 0 then DateDiff(MONTH, BirthDate, GetDate())
When DATEDIFF(DAY, BirthDate, GetDate()) > 0 then DateDiff(DAY, BirthDate, GetDate()) end Age,
Case When DateDiff(Year, BirthDate, GetDate()) > 0 then '岁'
When DateDiff(Month, BirthDate, GetDate()) > 0 then '月'
When DATEDIFF(DAY, BirthDate, GetDate()) > 0 then '日' end AgeUnit, BirthDate BirthDate
From 人员信息表
转载于:https://www.cnblogs.com/meitai/p/9175782.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
