Yeah, what day does the week start? Sunday, or Monday?
datepart( dw, date) returns the day of the week (1 to 7), but "[t]he number produced by the weekday datepart depends on the value set by SET DATEFIRST, which sets the first day of the week."
But it'll return the right thing, assuming your database is properly set up.
OK, if it returns 1, we're on the first day, or more generally, the first day is
1 - datepart( dw, date) days before our date
If it returns 7 we're at the last day of the week, or more generally, the last day is
7 - datepart( dw, date ) days after our date
We use dateadd( dd, n, date) to get a date n days from our date, so:
select
date_column,
datepart(wk, date_column ) as week_number,
dateadd( dd, 1 - datepart( dw, date_column ),date_column ) as week_start,
dateadd( dd, 7 - datepart( dw, date_column ), date_column ) as week_end
from table ;
gives us what we need.
Note that the first day of the first week of a year night be in the previous calendar year, because by definition a week starts on (Sunday or Monday or whatever you've set it to be), but a year can start on any day of the week. Similarly, the last day of the last week of the year might be in the next calendar year.