// get the first day of month
DateTime mstartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
//get the last day of month
DateTime mendDate = mstartDate.AddMonths(1);
mendDate = mendDate.AddDays(-1);
int wrkdays = 0;
string[] wekend = new string[31];
Participant
1473 Points
625 Posts
code to get the no of weeks in a month & no of working days
Feb 19, 2009 07:07 AM|chezhian_in05|LINK
// get the first day of month
DateTime mstartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
//get the last day of month
DateTime mendDate = mstartDate.AddMonths(1);
mendDate = mendDate.AddDays(-1);
int wrkdays = 0;
string[] wekend = new string[31];
int wkcnt = 0;
for (DateTime dd = mstartDate; dd <= mendDate; dd = dd.AddDays(1))
{
if ((dd.DayOfWeek > DayOfWeek.Sunday) )
{
if ((dd.DayOfWeek != DayOfWeek.Saturday))
{
wrkdays = wrkdays + 1;
}
else
{
wkcnt = wkcnt + 1;
if (wrkdays > 0)
{
htw.Add(dd.AddDays(-1).ToShortDateString(), wrkdays);
wrkdays = 0;
}
}
}
}
where Hashtable will have records as below
"2/13/2009" "5"
"2/27/2009" "5"
"2/20/2009" "5"
"2/6/2009” "5"
[idea]
R.Chezhian.,
=============================================
Please Mark the helpful post(s) as Answered