使用以下内容作为基础,我将如何计算一个人的几个月年龄
IF cast(datepart(m, GETDATE()) as int) > cast(datepart(m,@in_DOB) as int)
SET @age = cast(datediff(yyyy,@in_DOB,GETDATE()) as int)
else
IF cast(datepart(m,GETDATE()) as int) = cast(datepart(m,@in_DOB) as int)
IF datepart(d,GETDATE()) >= datepart(d,@in_DOB)
SET @age = cast(datediff(yyyy,@in_DOB,GETDATE()) as int)
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,GETDATE()) as int) -1
ELSE
SET @age = cast(datediff(yyyy,@in_DOB,GETDATE()) as int) - 1
RETURN @age