I need to calculate the number of full years between two dates in sql. The query that I use to calculate is
--Date1 > Date2
CASE
WHEN YEAR(Date1) = YEAR(Date2)
THEN DATEDIFF(year, Date2, Date1)
WHEN YEAR(Date1) > YEAR(Date2)
AND MONTH(Date1) >= MONTH(Date2)
AND DAY(Date1) >= DAY(Date2)
THEN DATEDIFF(year, Date2, Date1)
ELSE
DATEDIFF(year, Date2, Date1) - 1
However, I need to somehow configure it so that it considers the time between 1/5/2011 and 30/4/2012 as 1 full year.
source
share