Getting all DateTimes between two 'DateTime's in C#

前端 未结 8 673
清酒与你
清酒与你 2020-12-12 20:14

I have two DateTimes, and I want to get all DateTimes between these Dates. Such as, if my Dates are like 01.01.2010 - 05.01.2010, my function shoul

8条回答
  •  醉话见心
    2020-12-12 20:40

    You can use DateTime objects directly in the loop, in place of your int. DateTime.AddDays handles month ends correctly.

    for (DateTime date = startingDate; date <= endingDate; date = date.AddDays(1))
        allDates.Add(date);
    

提交回复
热议问题