SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

oasis1
Starting Member

33 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
5937 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  
 New 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