In this post we will create a Stored Procedure that calculates age. In the procedure we will use datediff function
Example 1
1 2 3 4 5 6 7 8 9 10 |
Create Procedure SP_Age_Calculate(@birthdate datetime,@age int output) as Begin Set @age = DATEDIFF(yy,@birthdate,getdate()) End -- First Execute the code above, if you get successful message, then you can learn the age of you entered birthdate Declare @age int Execute SP_Age_Calculate '10.04.1984',@age output Select @age |
Result: 36