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
 General SQL Server Forums
 New to SQL Server Programming
 Calculating Age Between dates

Author  Topic 

Kotti
Posting Yak Master

129 Posts

Posted - 2009-08-21 : 01:18:05
Hi Friends,

I had table which has a field called dateofbirth of varchar type.

Now i need to calculate the age and select between two ages

My table has
id dateofbirth
1 04/30/1980
2 6/3/1986
3 6/3/1985
4 6/3/1984
5 6/3/1983

here when i use the below query i can get the age,but i need the ages between 18 to 23 .How can i get that?

SELECT DATEDIFF(year, dateofbirth ,getdate()) as NoOfYear
from Table1

Thanks

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-21 : 01:21:13
Try this once,

select * from table where DATEDIFF(year, dateofbirth ,getdate()) between 18 and 23
Go to Top of Page

Kotti
Posting Yak Master

129 Posts

Posted - 2009-08-21 : 01:28:04
quote:
Originally posted by Nageswar9

Try this once,

select * from table where DATEDIFF(year, dateofbirth ,getdate()) between 18 and 23



Thanks Nageshwar,

I didn't think this simple thing.

Once again thanks for you.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-21 : 01:29:07
quote:
Originally posted by Kotti

quote:
Originally posted by Nageswar9

Try this once,

select * from table where DATEDIFF(year, dateofbirth ,getdate()) between 18 and 23



Thanks Nageshwar,

I didn't think this simple thing.

Once again thanks for you.




Ok, Welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-21 : 01:34:10
Also refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -