Created
January 18, 2016 09:05
-
-
Save johnparn/a624d7c51c691b99940b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get age from birthdate | |
select ( | |
case when | |
datepart(year,[BirthDate])>(1900) | |
AND datepart(year,[BirthDate])<datepart(year,getdate()) | |
AND (datepart(month,[BirthDate])>=(1) | |
AND datepart(month,[BirthDate])<=(12)) | |
AND (datepart(day,[BirthDate])>=(1) | |
AND datepart(day,[BirthDate])<=(31)) | |
then | |
case isdate(CONVERT([datetime],[BirthDate],(0))) | |
when (1) | |
then floor(datediff(dayofyear,[birthdate],getdate())/(365.25)) | |
when (0) | |
then NULL | |
end | |
end) | |
as age | |
from person |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment