I believe the following logic does what you want:
datediff(year,
@START_DATE - datepart(dayofyear, @START_DATE) + 1,
@END_DATE - datepart(dayofyear, @START_DATE) + 1
) as d2
Note: This treats that dates as datetime
, because arithmetic is easier to express. You can also write this as:
datediff(year,
dateadd(day, - datepart(dayofyear, @START_DATE) + 1, @START_DATE),
dateadd(day, - datepart(dayofyear, @START_DATE) + 1, @END_DATE)
) as d2
The following query is a demonstration:
select datediff(year,
startdate - datepart(dayofyear, startdate) + 1,
enddate - datepart(dayofyear, startdate) + 1
) as d2
from (select cast('2004-02-01' as datetime) as startdate,
cast('2014-01-31' as datetime) as enddate
union all
select cast('2004-02-01' as datetime) as startdate,
cast('2014-02-01' as datetime) as enddate
) t