-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
DROP PROCEDURE age
GO
CREATE PROCEDURE age(@birthday DATETIME)
AS
SELECT YEAR(GETDATE())-YEAR(@birthday)-CASE WHEN DATEPART(dy,GETDATE())<DATEPART(dy,@birthday) THEN 1 ELSE 0 END
RETURN
GO
EXEC AGE '17-SEP-2005'
GO
EXEC AGE '18-SEP-2005'
GO
EXEC AGE '19-SEP-2005'
GO
