Tuesday, July 1, 2014

DateTime getting the duration from each element within two lists(start time/end time)

This is one way to do it:



var list1 = new List<DateTime> {DateTime.Now, DateTime.Now.AddMinutes(10), DateTime.Now.AddMinutes(20)};
var list2 = new List<DateTime> {DateTime.Now.AddMinutes(10), DateTime.Now.AddMinutes(20), DateTime.Now.AddMinutes(30)};
var results = new List<TimeSpan>();

for (int i = 0; i < Math.Min(list1.Count, list2.Count); i++)
{
results.Add(list2[i].Subtract(list1[i]));
}


No comments:

Post a Comment