Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Calculating Age from Birthdate

Author  Topic 

omega1983
Starting Member

40 Posts

Posted - 2009-12-07 : 12:41:32
I have a birthdate in the following format
birthmonth(char(2)
birthday char(2)
birthyear char(4)
Our database shows these three as text instead of datetime.
Two objectives:
I want to concatenate the three birth fields so they display like this
mm/dd/yyyy (01/01/1985)
I also want to use the above date format to calculate the present age of the person. For example if the birthday is 12/1/1985, they just turned 24. If their birthday is 12/24/1985 they turn 24 on the 24th.

Is there a way to do this in SQL. So the final results look like this
ID NAME birthday age
12 Johnson 12/1/1985 24
13 Smith 12/24/1985 23

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-07 : 12:45:47
Datediff(dd,convert(datetime,22211.0028),Getdate())/365.00 As Years



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-07 : 13:39:29
You could have pointed the OP to your profile link

quote:
Originally posted by X002548

Datediff(dd,convert(datetime,22211.0028),Getdate())/365.00 As Years



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam





Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-07 : 19:19:26
see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762&SearchTerms=Finding%20Age


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -