1

I have a datetimepicker control in winform which I am creating in c#.

How would I get the week number of the month when I select a date in datetimepicker control in c#?

That means, If I select the date as 09/09/2014 then the result should be shown in next textbox control as 2nd week of the month in the winform.

Please help me out.

Shiva Debrown
  • 167
  • 4
  • 5
  • 20

3 Answers3

1
var month = datetimepicker.Value.Month;
var weekNumberThisMonth = (datetimepicker.Value.Day + (7 - (int)datetimepicker.Value.DayOfWeek)) / 7;
Simon Farshid
  • 2,636
  • 1
  • 22
  • 31
1

There is a simpler way to do this :

 private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
   txtweek.Text=  (1+(dateTimePicker1.Value.Day / 7)).ToString("0");
}
karim
  • 167
  • 1
  • 1
  • 6
0

txtweek.Text= (1+(dateTimePicker1.Value.Day / 7)).ToString("0");

This is my answer

Shiva Debrown
  • 167
  • 4
  • 5
  • 20