Creating a Date range from a list of dates
<p>I am trying to create a set of date ranges from a list of dates. </p>

<p>These dates are present in my object. Basically I would iterate through each row and will keep on iterating and when the time-span difference is greater than 5 minutes I will stop and use the end points as a date range. I have an algorithm below but the problem is it excludes many data rows:</p>

<p>Please see below the sample data and desired output</p>

<pre><code>**Sample Data**

  Start_Date   Start_Date_Time    Replicate
    12.12.2012   8:22:58            10
    12.12.2012   8:22:58            30
    12.12.2012   8:22:58            31
    12.12.2012   8:22:58            32
    12.12.2012   8:22:58            33
    12.12.2012   8:22:58            34 
    12.14.2012   9:49:27            54
    12.14.2012   9:49:27            55
    12.14.2012   9:49:27            78
    12.14.2012   9:49:27            99
    12.14.2012   9:58               120
    12.14.2012   9:58               140
    12.14.2012   9:58               142
    12/12/2012   9:59               144
    12/12/2012   9:59               146
    12/12/2012   9:59               148
    12/12/2012   9:59               150

**Desired Output**
Date Ranges
8:22:58-8:22:58   Replicate10-34
9:49:27-9:49:27   Replicate54-99
9:58-9:59         Replicate120-150
</code></pre>

<p>My code gives me results but it excludes many rows:</p>

<pre><code>lf.ReplicateBlocks.OrderBy(x =&gt; x.InitiationDate);
</code></pre>

<p>The initiationDate above is the StartDate and Start Time. I have sorted the list above in ascending order to start from the minimum date/time:</p>

<pre><code> DateTime minimumDateTime = DateTime.MinValue;

 foreach (RunLog.Domain.Entities.ReplicateBlock rb in lf.ReplicateBlocks)
 {
   TimeSpan intervalMinutes = rb.InitiationDate.Subtract(minimumDateTime);

   if (intervalMinutes.TotalMinutes &gt;= 5)
   {
     minimumDateTime = rb.InitiationDate;

     //minDates.Add(minimumDateTime);

     UserConfirmationErrors confirmationRun = new UserConfirmationErrors();
     confirmationRun.minDate = rb.InitiationDate;
     confirmationRun.replicateID = rb.ReplicateId;

     uc.userConfirmationList.Add(confirmationRun);
   }
 }

 List&lt;RunLog.Domain.Entities.RunLogEntryDatesDisplay&gt; reDisplay = new List&lt;Domain.Entities.RunLogEntryDatesDisplay&gt;();

 foreach (var minDate in uc.userConfirmationList)
 {
   RunLog.Domain.Entities.RunLogEntryDatesDisplay red = new Domain.Entities.RunLogEntryDatesDisplay();
   reDisplay.Add(new Domain.Entities.RunLogEntryDatesDisplay() { runDate = minDate.minDate, DateRange = string.Format("{0} - {1}", minDate.minDate, minDate.minDate.AddMinutes(5)), MinimumReplicateId = minDate.replicateID.ToString() });
 }

 //return reDisplay.OrderByDescending(t =&gt; t.runDate).ToList();
 return reDisplay;
</code></pre>

<p>Once the user Confirmation List with Date Ranges is formed, I send it to the view in the form of a checkbox list, users selects those dates and I take the selected dates and look for those records again below:</p>

<pre><code>  var query = from d in selectedDates
                    from o in lf.ReplicateBlocks
                    where (d.Checked &amp;&amp;
                          o.InitiationDate &gt;= d.runDate &amp;&amp;
                          o.InitiationDate &lt;= d.runDate.AddMinutes(5))
                    select o;
</code></pre>
