How to loop between two dates

后端 未结 5 1353
面向向阳花
面向向阳花 2021-02-04 02:12

I have a calendar which passes selected dates as strings into a method. Inside this method, I want to generate a list of all the dates starting from the selected start date and

5条回答
  •  离开以前
    2021-02-04 02:47

    You just need to iterate from start to end, you can do this in a for loop

    DateTime start = DateTime.Parse(startDate);
    DateTime end = DateTime.Parse(endDate);
    
    for(DateTime counter = start; counter <= end; counter = counter.AddDays(1))
    {
        calculatedDates.Add(counter);
    }
    

提交回复
热议问题