title: Find max and min DateTime in Linq group
body: <p>I'm trying to find the max and min <code>DateTime</code>s from a CSV import.</p>
  
  <p>I have this to import the data from the temp <code>DataTable</code>:</p>
  
  <pre><code>var tsHead = from h in dt.AsEnumerable()
           select new
                      {
                          Index = h.Field&lt;string&gt;("INDEX"),
                          TimeSheetCategory = h.Field&lt;string&gt;("FN"),
                          Date = DdateConvert(h.Field&lt;string&gt;("Date")),
                          EmployeeNo = h.Field&lt;string&gt;("EMPLOYEE"),
                          Factory = h.Field&lt;string&gt;("FACTORY"),
                          StartTime = DdateConvert(h.Field&lt;string&gt;("START_TIME")), //min
                          FinishTime = DdateConvert(h.Field&lt;string&gt;("FINISH_TIME")), //max
                      };
  </code></pre>
  
  <p>Which works fine. I then want to group the data and show the Start time and finish time which is the min / max of the respective fields.</p>
  
  <p>So far I have this:</p>
  
  <pre><code>var tsHeadg = from h in tsHead
                        group h by h.Index into g //Pull out the unique indexes
                        let f = g.FirstOrDefault() where f != null
                        select new
                                   {
                                       f.Index,
                                       f.TimeSheetCategory,
                                       f.Date,
                                       f.EmployeeNo,
                                       f.Factory,
                                       g.Min(c =&gt; c).StartTime, //Min starttime should be timesheet start time
                                       g.Max(c =&gt; c).FinishTime, //Max finishtime should be timesheet finish time
                                   };
  </code></pre>
  
  <p>With the thinking that <code>g.Min</code> and <code>g.Max</code> would give me the lowest and highest <code>DateTime</code> for each timesheet (grouped by index)</p>
  
  <p>This doesn't work however...  Whats the best way of finding the highest and lowest value of DateTimes within a group?</p>