Hi Everyone,Just wanted to check with everyone.Need a function to calculate the first day of the week (sun) for a given week number. Here's my first stab at it.DECLARE @year int = 2010DECLARE @cw int = 30DECLARE @yearOffset int = 1900DECLARE @offset int = -((@year-@yearOffset)%7)DECLARE @dayOfYear smalldatetime = CONVERT(smalldatetime,(7*(@cw))) -- year is 1900 by defaultDECLARE @currentDate smalldatetime = DATEADD(yy,(@year-@yearOffset),@dayOfYear) -- add offset to 1900DECLARE @startOfWeek smalldatetime = DATEADD(dd,@offset,@currentDate) -- calc sunday startSELECT @startOfWeek-- one linerSELECT DATEADD(dd,-((@year-1900)%7),DATEADD(yy,(@year-1900),CONVERT(smalldatetime,(7*(@cw)))))
Let me know if there are any errors.