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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Datediff issue
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

oasis1
Starting Member

35 Posts

Posted - 11/06/2013 :  11:34:38  Show Profile  Reply with Quote
Hi all I am trying to use a datediff to get the age of a patient at a certain time of year.

They want to set the persons age as of 06302012. This eems simple enough but I get erroneous data

I use the following datediff(YY, PAT.BIRTH_DATE, '20120630') but even if the person birth day comes after June 30 it returns the age for that year regardless of the date

example
bdate
02/01/2010 age will equal 2
08/01/2010 age should be 1 but comes out as 2...

mahalo, for your help

TG
Flowing Fount of Yak Knowledge

USA
6065 Posts

Posted - 11/06/2013 :  11:39:16  Show Profile  Reply with Quote
Here's the ultimate age function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462

EDIT:
but this simple hack will work some of the time:
floor(datediff(day, PAT.BIRTH_DATE, '20120630') / 365.0)

Be One with the Optimizer
TG

Edited by - TG on 11/06/2013 11:48:47
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000