此问题在此处已有答案:
How to calculate age (in years) based on Date of Birth and getDate()(39个答案)
11天前关闭。
我有一个以DateTime格式存储患者出生日期的表(2022-06-22)。
我怎样才能得到七月出生的人的年龄?
我试过下面的:
select sFirstName,
sLastName,
dDateOfBirth,
DATEDIFF(yy,dDateOfBirth,GETDATE()) as Age,
ifkMedicalAidID
from Patients
where DATEDIFF(month,dDateOfBirth,GETDATE()) between 5 and 5
虽然我只得到了七月的所有记录(这是正确的),所有年龄都是0,但我看到了上述查询的问题,但我没有SQL知识来解决它...
2条答案
按热度按时间o2rvlv0m1#
mmvthczy2#
这个管用,谢谢约翰