Hello. I have two DateTime, 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 should return me a list of date (List) and it must contains 01.01.2010, 02.01.2010, 03.01.2010, 04.01.2010, 05.01.2010 I wrote a function like this. It works fine, if my dates in a month. It wont work if my dates be like 01.01.2010 - 05.02.2010. Because the month changed, and my function cant handle it. Is there any function in C# returns me all dates between two date? Or how can I handle month change?
public void GetAllDatesAndInitializeTickets(DateTime startingDate, DateTime endingDate)
{
List<DateTime> allDates = new List<DateTime>();
int starting = startingDate.Day;
int ending = endingDate.Day;
for (int i = starting; i <= ending; i++)
{
allDates.Add(new DateTime(startingDate.Year, startingDate.Month, i));
}
EDIT: Question solved, see Tim Robinson's simple answer to use.