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
 General SQL Server Forums
 New to SQL Server Programming
 Working out Years diff
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Robowski
Posting Yak Master

101 Posts

Posted - 10/01/2013 :  07:24:36  Show Profile  Reply with Quote
Just wondering, what you all consider to be the most efficient way for working out years? for example:

SELECT DATEDIFF(Year, CAST('01/02/1985' as datetime), CAST('01/01/1995' as datetime)) returns 10 this isn't actually correct in terms of how old that person is

SELECT DATEDIFF(Year, CAST('01/02/1985' as datetime), CAST('01/01/1995' as datetime)) / 12 returns 9 which is correct if you purely want to know the year but haven't looked at this over large amounts of data.

SELECT DATEDIFF(day, CAST('01/02/1985' as datetime), CAST('01/01/1995' as datetime)) / 365.4 gives 9.909688

without doing some testing about different points of the year etc, does has one looked into this?

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 10/01/2013 :  08:57:52  Show Profile  Reply with Quote
SELECT  ( CAST(CONVERT(CHAR(8), GETDATE(), 112) AS INT)
          - CAST(CONVERT(CHAR(8), DateOfBirth, 112) AS INT) ) / 10000
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.03 seconds. Powered By: Snitz Forums 2000