0

Using SQL Server 2008 R2

I have a database of my friend's project. He used varchar to store date of birth of members because he was getting errors parsing entries to date. I want to show the age using a procedure code.

the format of date stored in mm/dd/yyyy where today's date is stored as 3/4/2016 . I wanted to use DATEDIFF function but it is not a good option with varchar.

1 Answers1

0
Create procedure spCalculateAge
@dob varchar(10)
as
Begin
Select DATEDIFF(year,Convert(date,@dob),getdate()) as Age
End

I used this and it worked. Before it was giving conversion error but opening and closing SQL Server caused it to work.