Dot Net Learning Zone Blog

A blog about to learn Dot Net

How to count week in month

Posted by Rajesh on February 5, 2009

  public int GetWeekInMonth(int year, int month)

        {

            CultureInfo cinfo = CultureInfo.CurrentCulture;

            Calendar MyCal = CultureInfo.InvariantCulture.Calendar;

            int CountWeek = 0;

            for (int icount = 1; icount < cinfo.Calendar.GetDaysInMonth(year, month); icount++)

            {

                string str = Convert.ToString(MyCal.GetDayOfWeek(new DateTime(year, month, icount)));

                if (str.Equals(“Monday”, StringComparison.OrdinalIgnoreCase))

                {

                    CountWeek = CountWeek + 1;

                }

 

            }

            return CountWeek;

        }

 

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>