This snippet of code shows how to get Month and Year between two dates. The code below return an array of ListItems.
Sample Output:
June 2010
July 2010
August 2010
September 2010
October 2010
November 2010
December 2010
January 2011
February 2011
public ArrayList GetMonthYear(DateTime dtStart, DateTime dtEnd)
{
ArrayList monthList = new ArrayList();
for (DateTime dt = dtStart; dt <= dtEnd; dt = dt.AddMonths(1))
{
monthList.Add(new ListItem(dt.ToString("MMMM yyyy"), dt.ToString("yyyy")));
}
return monthList;
}
{
ArrayList monthList = new ArrayList();
for (DateTime dt = dtStart; dt <= dtEnd; dt = dt.AddMonths(1))
{
monthList.Add(new ListItem(dt.ToString("MMMM yyyy"), dt.ToString("yyyy")));
}
return monthList;
}
Sample Output:
June 2010
July 2010
August 2010
September 2010
October 2010
November 2010
December 2010
January 2011
February 2011
No comments:
Post a Comment