December 20, 2012 at 4:24 am
Hi All
I have a query to fetch the starting day as "Monday" between any 2 selected dates.
For eg:
Start Date is : 08/12/2012
End Date is 08/19/2012
and I wanted the output as:
Date start of week
08/12/2012 08/06/2012 ----------------that is the Monday
08/13/2012 08/13/2012--------start day Monday
08/14/2012 08/13/2012-Monday
....
08/19/2012 08/13/2012
I use the below query as of now
(select DISTINCT Date_Column,CONVERT(date, DATEADD(wk, DATEDIFF(wk, 0, DATEADD(d, - 1,Date_Column)), 0), 103) AS Week,DATEPART(Week,Date_Column) as Week_Num
from dbo.date_dim
where convert(date,Date_Column,103) BETWEEN
dateadd(wk, datediff(Wk, 0, DATEADD(dd,-1,'08/12/2012')), 0)
AND dateadd(wk, datediff(wk, 0, DATEADD(dd,-1,'08/19/2012')), 0)
)
I know my query returns wrong results...could any 1 please know how to achieve the result.
Thanks
December 20, 2012 at 4:27 am
My where clause should be just between startdate and enddate...but wheras I have use start of week also in the where clause...
I hope wat I had figured out is right..
Thanks
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply