Calculate DateTime Weeks into Rows | 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:



```
var iWeeks = 6;
for (int w = 0; w < iWeeks; w++) {

```

This works fine, however, some month will only have 5 weeks and in some rare cases, 4.


How can I calculate the number of rows that will be required for a particular month?


This is an example of what I am creating:


![enter image description here](https://i.stack.imgur.com/NkxN7.png)


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.


***Image found on google***




---


This is an example of what I am creating:


![enter image description here](https://i.stack.imgur.com/NkxN7.png)


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.


***Image found on google***