title: Calculate DateTime Weeks into Rows
body: <p>I am currently writing a small calendar in ASP.Net C#. Currently to produce the rows of the weeks I do the following for loop:</p>
  
  <pre><code>var iWeeks = 6;
  for (int w = 0; w &lt; iWeeks; w++) {
  </code></pre>
  
  <p>This works fine, however, some month will only have 5 weeks and in some rare cases, 4.</p>
  
  <p>How can I calculate the number of rows that will be required for a particular month?</p>
  
  <p>This is an example of what I am creating:</p>
  
  <p><img src="https://i.stack.imgur.com/NkxN7.png" alt="enter image description here"></p>
  
  <p>As you can see for the above month, there are only 5 rows required, however. Take the this month (August 2008) which started on a Saturday and ends on a Monday on the 6th Week/Row.</p>
  
  <p><strong><em>Image found on google</em></strong></p>
  
  <hr>
  
  <p>This is an example of what I am creating:</p>
  
  <p><img src="https://i.stack.imgur.com/NkxN7.png" alt="enter image description here"></p>
  
  <p>As you can see for the above month, there are only 5 rows required, however. Take the this month (August 2008) which started on a Saturday and ends on a Monday on the 6th Week/Row.</p>
  
  <p><strong><em>Image found on google</em></strong></p>