This article explains how to get all weeks in a month with start and end date.
Output Sample:
If _year = 2012 and _month = 04, the output would be
01-04-2012 - 07-04-2012
08-04-2012 - 14-04-2012
15-04-2012 - 21-04-2012
22-04-2012 - 28-04-2012
29-04-2012 - 05-05-2012
public ArrayList GetWeeks(int _year, int _month)
{
int countDays = DateTime.DaysInMonth(_year, _month);
ArrayList _weeksList = new ArrayList();
for (int i = 1; i <= countDays; i = i + 7)
{
DateTime _startDate = new DateTime(_year, _month, i);
DateTime _finishDate = _startDate.AddDays(6);
string sReturn = _startDate.ToShortDateString()
+ " - " + _finishDate.ToShortDateString();
_weeksList.Add(sReturn);
}
//zero-based array
return _weeksList;
}
{
int countDays = DateTime.DaysInMonth(_year, _month);
ArrayList _weeksList = new ArrayList();
for (int i = 1; i <= countDays; i = i + 7)
{
DateTime _startDate = new DateTime(_year, _month, i);
DateTime _finishDate = _startDate.AddDays(6);
string sReturn = _startDate.ToShortDateString()
+ " - " + _finishDate.ToShortDateString();
_weeksList.Add(sReturn);
}
//zero-based array
return _weeksList;
}
Output Sample:
If _year = 2012 and _month = 04, the output would be
01-04-2012 - 07-04-2012
08-04-2012 - 14-04-2012
15-04-2012 - 21-04-2012
22-04-2012 - 28-04-2012
29-04-2012 - 05-05-2012