andre72
asked on
Loop from one year to an other by every month
Hi,
I need to loop from one moth of a year to an other moth of an other year, eg.:
Startmonth: 2010-06-01
Endmonth: 2011-03-01
So loop:
2010-06
...
2010-11
2010-12
2011-01
2011-02
...
How can I do a loop like this?
Thanks
Andre
I need to loop from one moth of a year to an other moth of an other year, eg.:
Startmonth: 2010-06-01
Endmonth: 2011-03-01
So loop:
2010-06
...
2010-11
2010-12
2011-01
2011-02
...
How can I do a loop like this?
Thanks
Andre
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Please try following code:
Thanks
Please try following code:
DateTime Startmonth = new DateTime(2010,6,1);
DateTime Endmonth = new DateTime(2011, 3, 1);
DateTime dt = new DateTime(Startmonth.Year, Startmonth.Month, 1); // also equals to Startmonth
while (dt < Endmonth)
{
MessageBox.Show(dt.ToString("yyyy-MM"));
dt = dt.AddMonths(1);
}
Thanks
ASKER
Thanks
DateTime endDate = DateTime.Parse("8/8/2010")
for (DateTime i = startDate; i <= endDate; i = i.AddMonths(1))
{
MessageBox.Show(i.ToString
}