-6

I need to find week number in a month. It could be 4 or 5 weeks in a month (depending on the calendar) and I need to find the week number based on the current date. Note : (Day)/7 would not work since Week 1 or Week 4 would be assumed to have 7 days which is not always the case.

Megh R
  • 1

2 Answers2

0

Set the count to 1, and enumerate every day of a month. Add to count by 1 for each sunday except the first day. After the enumeration, the count is the number of weeks in that month.

Tiger Liu
  • 51
  • 4
0

just do like this

DateTime date =DateTime.Now;
int weekOfMonth=(date.Day + ((int)date.DayOfWeek)) / 7 + 1;

calculation based on Malaysia time is (today number is 13 + day of week is 2) divided by 7 and then add one to result so result would be 3

Saif
  • 2,611
  • 3
  • 17
  • 37