Hi,
I am haven problem trying to compare day from different years but I am trying to find the same day not date.
I have the following code so far but I there is something wrong not sure how to fix it but here is example.
Code
DECLARE @dteRequest AS DATETIME
Set @dteRequest = '06/14/2007'
select DATEADD(ww, DATEPART(ww, DATEADD(dd, -1, @dteRequest_Start)) - DATEPART(ww, @dteCompare_Start), @dteCompare_Start) as SameDayLastYear
OUTPUT = 2006-06-08 00:00:00.000
OUTPUT should be = 2006-06-15 00:00:00.000
Now if the year is 2007 day is off by week but I can change "DATEADD(dd, -1, @dteRequest_Start)" to "DATEADD(ww, 1, @dteRequest_Start)" and everything is fine but one problem, when the year changes to 2008 days are off again not sure how to fix this bug.
I just want to match the current day to last year day....
Sorry, hope I gave good example there, havent worked with dates to much.
Thanks
I am haven problem trying to compare day from different years but I am trying to find the same day not date.
I have the following code so far but I there is something wrong not sure how to fix it but here is example.
Code
DECLARE @dteRequest AS DATETIME
Set @dteRequest = '06/14/2007'
select DATEADD(ww, DATEPART(ww, DATEADD(dd, -1, @dteRequest_Start)) - DATEPART(ww, @dteCompare_Start), @dteCompare_Start) as SameDayLastYear
OUTPUT = 2006-06-08 00:00:00.000
OUTPUT should be = 2006-06-15 00:00:00.000
Now if the year is 2007 day is off by week but I can change "DATEADD(dd, -1, @dteRequest_Start)" to "DATEADD(ww, 1, @dteRequest_Start)" and everything is fine but one problem, when the year changes to 2008 days are off again not sure how to fix this bug.
I just want to match the current day to last year day....
Sorry, hope I gave good example there, havent worked with dates to much.
Thanks