Thursday, March 27, 2014

return the end of week date using month and week number

You can easily achieve with a calendar table, if you have one.


or else use below..



DECLARE @WeekNo int= 14, @YearMonth int=201401

SELECT DATEADD(wk,@WeekNo-1,DATEADD(yy,LEFT(@YearMonth, 4)-1900,0)) AS WeekStart,
DATEADD(wk,@WeekNo,DATEADD(yy, LEFT(@YearMonth, 4)-1900,0)) AS WeekEnd

Please mark as answer, if this has helped you solve the issue.


Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.





No comments:

Post a Comment