I have two DateTime s and I want to get all DateTime between these dates. For example, if my Dates are similar from 01/01/2010 - 01/05/2010, my function should return a list of dates (List) to me, and it should contain 01/01/2010, 01/02/2010, 01/03/2010, 01/04/2010, and 01/05/2010 .
I wrote such a function. It works great if my dates are per month. This will not work if my dates coincide from 01/01/2010 - 02/05/2010. Because the month has changed, and my function cannot handle it. Is there a function in C # that returns all dates between two dates? Or how can I handle month changes?
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)); }
Question resolved; see Tim Robinson, simple answer to use.
c # datetime
Serkan Hekimoglu Jul 12 '10 at 11:11 2010-07-12 11:11
source share