On Jun 5, 12:01 pm, Mike P <mike.p...@gmail.comwrote:
How do you take 2 dates (a startdate and an enddate), and then add all
the dates between them to an ArrayList?
This is as far as I have got so far, I'm not sure what to do next :
DateTime dtmStartDate = Convert.ToDateTime(dr["TaskStartDate"]);
DateTime dtmEndDate =
Convert.ToDateTime(dr["TaskEndDate"]);
TimeSpan ts = dtmEndDate - dtmStartDate;
arrTaskDates.Add(dtmStartDate);
If you look at my MiscUtil library (
http://pobox.com/~skeet/csharp/
miscutil) you'll find a range class, and a way of iterating through
any particular range. Combined with extension methods, you could
write:
dtmStartDate.To(dtmEndDate).Step(1.Days()).ToList( );
(Note that it would give you a List<Trather than an ArrayList.)
I *think* the Step stuff uses Marc Gravell's generic operator code
which requires .NET 3.5 (in the version checked into MiscUtil
currently). What version of .NET are you using? If you're still on 1.1
(which is possible given your wish to use ArrayList) you'll need to
write a loop such as:
for (DateTime date = dtmStartDate; date <= dtmEndDate; date =
date.AddDays(1))
{
list.add(date);
}
Jon