This is a stored procedure for calculating the age in Number of years and days
create procedure calculate_age
@birthday datetime
as
declare @yeardiff int
declare @daydiff int
declare @result varchar(100)
set @yeardiff = datediff(yy,@birthday,getdate())
if dateadd(yy,@yeardiff,@birthday) > getdate()
set @daydiff = datediff(dd,dateadd(yy,@yeardiff-1,@birthday),getdate())
else
set @daydiff = datediff(dd,dateadd(yy,@yeardiff,@birthday),getdate())
set @result = 'The age is '+convert(varchar,@yeardiff)+' years and '+ convert(varchar,@daydiff)+' days '
select @result