Prev: Help with query for consecutive years
Next: Return value from stored procedure that returns a recordset
From: qjlee on 27 May 2010 15:53 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 27 May 2010 16:06 SELECT DATEDIFF(YY, @BirthDate, CURRENT_TIMESTAMP) AS AgeInYears -Eric Isaacs
From: Bob Barrows on 27 May 2010 16:27 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 27 May 2010 17:54 -- 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 27 May 2010 18:37 >> 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.
|
Next
|
Last
Pages: 1 2 Prev: Help with query for consecutive years Next: Return value from stored procedure that returns a recordset |