sql - How to convert a week (200851) into a date (2008-12-27)? -


How do I change a year's week (like 0852 or 200852) to a date (like 2008-12- 31, or especially on the weekend of a week i.e. Saturday 2008-12-27 or early one week i.e. 2008-12-21)? On any day of the end of the week, on Friday, Saturday, Sunday or Monday.

MS SQL server should help DATEADD functionallity ...

  DECLARE @date_string NCHAR (6) SELECT @date_string = N'200852 'SELECT DATEADD (WEEK, CAST (right (@tt_string, 2) as INT), DATEADD (YEAR, CAST (LEFT (@date_string, 4) INT ) - Edit:  

Sorry, I missed a little bit about making it a Saturday, etc ...

/ P>

Once you have the value, use DATEPART, which day of the week is obtained, and reduce it from your answer ...

  DECLARE @new_date DATETIME SELECT @new_date = '2008 Dec 30' SELECT DATEADD (DAY, 1-DATEPART (dw, @new_date), @new_date)  

This price will bring the start of the week In, based on determining you DATEFIRST


Comments