what is the most elegant way of showing first week in a month

Posted by ooo on Stack Overflow See other posts from Stack Overflow or by ooo
Published on 2010-05-17T11:38:43Z Indexed on 2010/05/17 12:00 UTC
Read the original article Hit count: 162

Filed under:
|
|
|

In C#, i want to show the first week in a calendar (in a html table) and i am trying to figure out the most elegant algorithm to generate the right days.

If the first day of the week is not Sunday, i want to show the days of preceding month (like you would see on a regular calendar). So, as an input you have a current month. In this case May. I want to generate this:

Month: May

 <table>
 <tr>
   <th>S</th>
   <th>M</th>
   <th>T</th>
   <th>W</th>
   <th>TH</th>
   <th>F</th>
   <th>Sa</th>
 </tr>
 <tr>
   <td>25</td>
   <td>26</td>
   <td>27</td>
   <td>28</td>
   <td>29</td>
   <td>30</td>
   <td>1</td>
 </tr></table>

so it should display something like this (ignore the alignment)

S | M | T | W | Th | F | Sa |
25 - 26 - 27 - 28 - 29 - 30 - 1

given that each month would have the start of day be a different day of the week, i am trying to figure out an elegant way to get the values of this data using the DateTime object. I see it has a dayofweek property on a date.

i am generating this table in C# on my server to pass down to a html page.

© Stack Overflow or respective owner

Related posts about c#

Related posts about date