Hello,
I have a case statement that calculates the age of a person as of 20090630. This is all hard coded and looks like this:
Age = Case When CASE WHEN dateadd(year, datediff(year, date_of_birth, '20090630'),
date_of_birth) > '20090630'
THEN datediff(year, date_of_birth, '20090630') - 1 ELSE datediff(year, date_of_birth, '20090630') END <1 then 0
ELSE CASE WHEN dateadd(year, datediff(year, date_of_birth, '20090630'),
date_of_birth) > '20090630'
THEN datediff(year, date_of_birth, '20090630') - 1 ELSE datediff(year, date_of_birth, '20090630') END end
What I would like to do is replace the hard coded date to say calculate the age as of 0630 (06/30) of any year.
Just can't seem to get this to work.....
Thanks for all your help!
I have a case statement that calculates the age of a person as of 20090630. This is all hard coded and looks like this:
Age = Case When CASE WHEN dateadd(year, datediff(year, date_of_birth, '20090630'),
date_of_birth) > '20090630'
THEN datediff(year, date_of_birth, '20090630') - 1 ELSE datediff(year, date_of_birth, '20090630') END <1 then 0
ELSE CASE WHEN dateadd(year, datediff(year, date_of_birth, '20090630'),
date_of_birth) > '20090630'
THEN datediff(year, date_of_birth, '20090630') - 1 ELSE datediff(year, date_of_birth, '20090630') END end
What I would like to do is replace the hard coded date to say calculate the age as of 0630 (06/30) of any year.
Just can't seem to get this to work.....
Thanks for all your help!