I want to to create somthing like this:
May, 2013
April, 2013
March, 2013
February, 2013
January, 2013
December, 2012
November, 2012
What I have written is this:
var currentDate = DateTime.Now;
var list = new List<ArchiveViewModel>();
for (var startDate = new DateTime(2013, 1, 1); startDate.Month <= currentDate.Month; startDate = startDate.AddMonths(1))
{
list.Add(new ArchiveViewModel
{
Month = startDate.Month,
Year = startDate.Year,
FormattedDate = startDate.ToString("MMMM, yyyy")
});
}
and ArchiveViewModel is this:
public class ArchiveViewModel
{
public int Month { get; set; }
public int Year { get; set; }
public string FormattedDate { get; set; }
}
However, it creates only months of a specific year (2012 or 2013):
January, 2013
February, 2013
March, 2013
April, 2013
May, 2013
and if I change the startDate to (2012,1,1) it will create this:
January, 2012
February, 2012
March, 2012
April, 2012
May, 2012
But what I want is this:
November,2012
December , 2012
January, 2013
February, 2013
March, 2013
April, 2013
May, 2013