Query to add Year to DateTime in SQL Server

Last Reply one year ago By dharmendr

Posted one year ago

Hi! I used below code, but could'n get required result:

declare @num int, @date date, @res int
set @date = '14.04.2017'
set @res = CONVERT(VARCHAR,CONVERT(INT,DATEDIFF(DD,@date,GETDATE())/365.25))
set @num = 0
while(@num <= @res)
	begin
		if(@num = 0)
			print @date
		else if(@num > 0)
			print DATEADD(year, 1, @date)
		set @num = @num + 1
	end

Result:

2017-04-14

2018-04-14

2018-04-14

I need below result:

2017-04-14

2018-04-14

2019-04-14

This question does not have replies that have been liked.