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)
 DATEDIFF?

Author  Topic 

fralo
Posting Yak Master

161 Posts

Posted - 2008-04-25 : 10:34:03
I need to get a listing of all persons who are atleast 18 years of age. A date of birth field in the database is in this format:

4/25/2008 12:00:00 AM

My solution would be where the difference between the current date and the dob is >= 18.

I tried...

select * from table where datediff(yy,dob,getdate)) >= 18.

But this only seems to subtract the years and ignore the days/months, which I need. Could anyone provide the syntax I need?

Help is appreciated. Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-25 : 10:39:53
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 10:48:16
http://www.sqlteam.com/article/datediff-function-demystified



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-25 : 17:38:27
Discussion continued in this thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101774

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -