From: qjlee on
I have a table called member, in which contains memberid and dob. How can I
calculate memberid's age based on DOB

Thanks,
qjlee
From: Eric Isaacs on
SELECT DATEDIFF(YY, @BirthDate, CURRENT_TIMESTAMP) AS AgeInYears

-Eric Isaacs
From: Bob Barrows on
qjlee wrote:
> I have a table called member, in which contains memberid and dob.
> How can I calculate memberid's age based on DOB
>
> Thanks,
> qjlee
http://weblogs.sqlteam.com/peterl/archive/2009/02/13/Improved-anniversary-calculation-better-datediff.aspx
--
HTH,
Bob Barrows


From: DavidC on

--
David


"qjlee" wrote:

> I have a table called member, in which contains memberid and dob. How can I
> calculate memberid's age based on DOB
>
> Thanks,
> qjlee

SELECT CASE
WHEN dob IS NULL THEN 0
WHEN dateadd(year, datediff (year, dob, getdate()), dob) > getdate()
THEN datediff (year, dob, getdate()) - 1
ELSE datediff (year, dob, getdate())
END As Age
FROM Member

HTH
David
From: --CELKO-- on
>> I have a table called member, in which contains member_id and dob.  How can I calculate member_id's age based on DOB <<

DATEDIFF (YEAR, dob, CURRENT_TIMESTAMP) AS member_age

but the better question is what do you mean? Asians use the year that
you are currently in as the person's age; Westerners use the count of
completed years of life. Consider a new-born baby: Asian system has
age 1 year, Westerner system has age 0 years and we use days, weeks
and months.