How do you iterate through every day of the year?

后端 未结 8 537
春和景丽
春和景丽 2020-12-05 09:23

Given a start date of 1/1/2009 and an end date of 12/31/2009, how can I iterate through each date and retrieve a DateTime value using c#?

Thanks!

8条回答
  •  既然无缘
    2020-12-05 10:05

    Set two variables:

    DateTime lowValue = DateTime.Parse("1/1/2009");
    DateTime highValue = DateTime.Parse("12/31/2009");
    

    Then, add a day to the low value until it is equal to highvalue:

    while (lowValue <= highValue)
    {
       //Do stuff here
       lowValue = lowValue.AddDays(1);
    }
    

    Or something like that.

提交回复
热议问题