I am trying to get the specific day of a Year.
Here's what I have tried till now:-
-- Declare few variables
DECLARE @Currentdate AS DATETIME
DECLARE @DueDate AS DATETIME
DECLARE @NewDate AS DATETIME
-- Set the variables properly, just for testing
SET @Currentdate = GETDATE()
SET @DueDate = DATEADD(MONTH, 2, DATEADD(YEAR, 1, @Currentdate))
-- Check the output
SELECT @Currentdate -- 2013-09-30 00:00:00.000
SELECT @DueDate -- 2014-11-30 00:00:00.000
So, I want to get the @NewDate
based on the @Currentdate
year.
For this I tried:-
SELECT @NewDate = DATEADD(DAY, DAY(DATEDIFF(day, 1, @DueDate)), DATEADD(MONTH, DATEDIFF(MONTH, 0, @Currentdate), 0))
SELECT @NewDate -- 2013-09-30 00:00:00.000
But it didn't worked. :(
My expected result is like:
-- 2013-11-30 00:00:00.000
-- Having the due date month and date same, but the year as current date one.
Any help is appreciated!
UPDATE
Sorry for all the confusion I have created. My question in simple words is:-
I want to get the a new date variable having the date and the month same as @DueDate
variable but the year as given in the @Currentdate
variable.
I hope that would clear things up a bit.