Correct week number from datepart
<p>The code returns:</p>

<pre><code>set datefirst 1
select datepart(wk,'2016-01-01')  - 1
</code></pre>

<p>but</p>

<pre><code>set datefirst 1
select datepart(wk,'2015-12-31')
</code></pre>

<p>returns..53 :/ </p>

<p>But in fact - this is the same week. There is more days belonging to 2015 in this week, so it should be "53" or "1" (the same value) for any dates in this particular week. Is this possible to avieve this without building dedicated procedure to analyse date and adjust returned value ? </p>

<p>I use SQL Server 2005</p>