PLease Help Get Age FRom DAte

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Im making this stored procedure to return the age of the user to the web
control but the problem is that DATEPART(). I can only Specify one and i need
the age to to the exact format of mm dd yy but i cant get it into the Query
so it can execute. And when I use the yyyy to return the Age it returns the
age as between 1 - 11 months and between 1 - 364 days. So for example the
user was
borned 21.11.85. when executed it returns the user is 20 when their 20th is
4months away.

<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @UName)
 
I'm not sure this would be acceptable in your situation as it's not exact -
but why not get the number of days old they are and divide by 365. That
should get you a years value that reflects the fact they may not have hit
their birthday yet this year.

Of course leap years throw this calculation off, but still should be pretty
close.
 
hi

was this a repeated post? included your correction
SELECT DATEDIFF(d, Dob, GETDATE()) / 364 AS Years,
( 12 - ( datepart(m, dob) - datepart(m,getdate()))) % 12 AS Months
FROM Basic
WHERE (UName = @UName)
 
Back
Top