Technical Article

Age

,

Function that will return a persons age.
Paramaters are todays date and date of birth.

CREATE  FUNCTION GetAge(@Today DateTime,@DateOfBirth DateTime)
RETURNS INT
AS
Begin
Declare @Age Int
Select  @Age =
((((Year(@Today) * 365) + DatePart(dy,@Today)) - 
         ((Year(@DateOfBirth) * 365) + DatePart(dy,@DateOfBirth))) 
   / 365)

Return @Age
End
Go

Select dbo.GetAge(GetDate(),'3/20/73')

Rate

3.5 (2)

Share

Share

Rate

3.5 (2)