DECLARE @s datetime,@e datetime
SET @s = '1978-2-24' --写你的生日
SET @e = getDate()+1
DECLARE @y int,@m int,@d int
SET @y = DATEDIFF(yy,@s,@e)
SET @s = DATEADD(yy,@y,@s)
SET @m = DATEDIFF(mm,@s,@e)
SET @s = DATEADD(mm,@m,@s)
IF @m<0
BEGIN
SET @y = @y-1
SET @m = @m+12
END
SET @d = DATEDIFF(dd,@s,@e)
IF @d<0
BEGIN
SET @m = @m -1
SET @d = @d + 32-Day(@e+32-Day(@e))
END
SELECT CAST(@y AS varchar(3))+'年'+CAST(@m AS varchar(2))+'月'+CAST(@d AS varchar(2))+'天'
SET @s = '1978-2-24' --写你的生日
SET @e = getDate()+1
DECLARE @y int,@m int,@d int
SET @y = DATEDIFF(yy,@s,@e)
SET @s = DATEADD(yy,@y,@s)
SET @m = DATEDIFF(mm,@s,@e)
SET @s = DATEADD(mm,@m,@s)
IF @m<0
BEGIN
SET @y = @y-1
SET @m = @m+12
END
SET @d = DATEDIFF(dd,@s,@e)
IF @d<0
BEGIN
SET @m = @m -1
SET @d = @d + 32-Day(@e+32-Day(@e))
END
SELECT CAST(@y AS varchar(3))+'年'+CAST(@m AS varchar(2))+'月'+CAST(@d AS varchar(2))+'天'