Possible Duplicate:
How to calculate age in T-SQL with years, months, and days
I have a problem with age calculation on Sql Server 2005. I have a customers table which has date of birth column
. What i want is to create view which has an age column
and this age column
should show the age of a person
by subtracting the date of birth from today(pretty simple).
I found a couple of good resources here but what i want exactly is to show the age by years and months. eg.(47 yrs, 3 months). This means i want to have both the year and month values and i want to add a string
(either 'years', 'yrs', 'y', 'months', 'mon', 'm', ...
) to the appropriate value and display it as eg. (25 years, 2 months
).
And if the person's age is just for example 3 months
, it should display '3 months
', not '0 years, 3 months
'.
If the person's age is some years without any months, it should display eg. '5 years
' not '5 years, 0 months
'
Oh, I have already done that using c# but i want to create a column on the sql view so that i can just populate my gridview using the view without doing any calculation on my c# code. If it helps i can post my c# code here. Thanks