title: How is first day of week determined in powershell?
body: <p>I have a scheduled task that runs a powershell script, which runs an executable with some parameters. One of the parameters is the current week number.</p>
  
  <p>I am using the following code in powershell to retrieve the weeknumber:</p>
  
  <pre><code>get-date -uformat %V
  </code></pre>
  
  <p>This seems to return an incorrect weeknumber </p>
  
  <ul>
  <li>2014-05-04 (sunday), returns week nr 18 (as expected)</li>
  <li>2014-05-05 (monday), returns week nr 18 (expected 19)</li>
  <li>2014-05-06 (tuesday), returns week nr 19 (as expected)</li>
  </ul>
  
  <p>In my registry the first day of week is set to Monday (HKEY_CURRENT_USER->Control Panel->International->iFirstDayOfWeek = 0)</p>
  
  <p>Does anyone know where powershell retrieves it's firstDayOfWeek setting from? Should (/can) I otherwise set it in the script?</p>
  
  <p>I know a workaround is to use .AddDays(1), but I'm looking for a neater solution.</p>
  
  <p>Edit:
  Ok this is really weird, I'm receiving different 'first day of week's for different years..</p>
  
  <p>2012 - On saturday:</p>
  
  <pre><code>PS C:\Users\A730978F&gt; get-date -date "2012-01-08" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-08 Sun Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-09" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-09 Mon Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-10" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-10 Tue Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-11" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-11 Wed Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-12" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-12 Thu Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-13" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-13 Fri Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2012-01-14" -uFormat "%Y-%m-%d %a Week: %V"
  2012-01-14 Sat Week: 3
  </code></pre>
  
  <p>2013 - On monday:</p>
  
  <pre><code>PS C:\Users\A730978F&gt; get-date -date "2013-01-06" -uFormat "%Y-%m-%d %a Week: %V"
  2013-01-06 Sun Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2013-01-07" -uFormat "%Y-%m-%d %a Week: %V"
  2013-01-07 Mon Week: 2
  PS C:\Users\A730978F&gt; get-date -date "2013-01-08" -uFormat "%Y-%m-%d %a Week: %V"
  2013-01-08 Tue Week: 2
  </code></pre>
  
  <p>2014 - On Tuesday:</p>
  
  <pre><code>PS C:\Users\A730978F&gt; get-date -date "2014-01-05" -uFormat "%Y-%m-%d %a Week: %V"
  2014-01-05 Sun Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2014-01-06" -uFormat "%Y-%m-%d %a Week: %V"
  2014-01-06 Mon Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2014-01-07" -uFormat "%Y-%m-%d %a Week: %V"
  2014-01-07 Tue Week: 2
  </code></pre>
  
  <p>2015 - On wednesday:</p>
  
  <pre><code>PS C:\Users\A730978F&gt; get-date -date "2015-01-04" -uFormat "%Y-%m-%d %a Week: %V"
  2015-01-04 Sun Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2015-01-05" -uFormat "%Y-%m-%d %a Week: %V"
  2015-01-05 Mon Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2015-01-06" -uFormat "%Y-%m-%d %a Week: %V"
  2015-01-06 Tue Week: 1
  PS C:\Users\A730978F&gt; get-date -date "2015-01-07" -uFormat "%Y-%m-%d %a Week: %V"
  2015-01-07 Wed Week: 2
  </code></pre>
  
  <p><em>(Note that I haven't tried all the weeks for every year)</em></p>
  
  <p>Edit2:</p>
  
  <p>After looking over the examples again, it seems the week number is based on the amount of '7 days' that have passed. I guess it doesn't actually use any 'first day of week' setting at all. I guess I'll have to make some calculation accordingly.</p>
  
  <p>Thanks for the help anyway!</p>