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 2008 Forums
 Transact-SQL (2008)
 Datediff issue

Author  Topic 

oasis1
Starting Member

35 Posts

Posted - 2013-11-06 : 11:34:38
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
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-11-06 : 11:39:16
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
Go to Top of Page
   

- Advertisement -