title: Put value in datatable group by week
body: <p>I have a datatable which comprises values from 1st January to march, something like this:</p>
  
  <pre><code>DATE        Employer    Job1    Job2
  1/4/2013        A        1.3    2
  1/4/2013        B        2.5    6
  1/6/2013        C        3.7    2.4
  1/7/2013        D        11 
  1/7/2013        F        334    0
  1/8/2013        A        1.87   1
  1/8/2013        B        6.85   2
  1/9/2013        C        58     226
  1/16/2013       A        9.43   1.45
  1/16/2013       B        5.27   0.6
  1/122/2013      C        45.4   5
  1/23/2013       A        44     4.78
  1/29/2013       B        45     40  
  2/2/2013        C        45     54.12
  2/2/2013        D         7     4.4587
  2/3/2013        F        265    11.486
  </code></pre>
  
  <p>Update:</p>
  
  <pre><code>DataTable datatable = new DataTable("Employee");
  
  datatable.Columns.Add("Date", typeof(string));
  datatable.Columns.Add("Employee", typeof(string));
  datatable.Columns.Add("Job1", typeof(double));
  datatable.Columns.Add("Job2", typeof(double));
  
  datatable.Rows.Add(new Object[] { "1/4/2013", "A", 1.3, 2 });
  datatable.Rows.Add(new Object[] { "1/4/2013", "B", 2.5, 6 });
  datatable.Rows.Add(new Object[] { "1/6/2013", "C", 3.7, 2.4 });
  datatable.Rows.Add(new Object[] { "1/7/2013", "D", 11, 0.0 });
  datatable.Rows.Add(new Object[] { "1/7/2013", "F", 334, 0 });
  datatable.Rows.Add(new Object[] { "1/8/2013", "A", 1.87, 1 });
  datatable.Rows.Add(new Object[] { "1/8/2013", "B", 6.85, 2 });
  datatable.Rows.Add(new Object[] { "1/9/2013", "C", 58, 226 });
  datatable.Rows.Add(new Object[] { "1/16/2013", "A", 9.43, 1.45 });
  datatable.Rows.Add(new Object[] { "1/16/2013", "B", 5.27, 0.6 });
  datatable.Rows.Add(new Object[] { "1/22/2013", "C", 45.4, 5 });
  datatable.Rows.Add(new Object[] { "1/23/2013", "A", 44, 4.78 });
  datatable.Rows.Add(new Object[] { "1/29/2013", "B", 45, 40 });
  datatable.Rows.Add(new Object[] { "2/2/2013", "C", 45, 54.12 });
  datatable.Rows.Add(new Object[] { "2/2/2013", "D", 7, 4.4587 });
  datatable.Rows.Add(new Object[] { "2/3/2013", "F", "265", 11.486 });
  datatable.Rows.Add(new Object[] { "3/3/2013", "A", "25", 28.124 });
  </code></pre>
  
  <p>I want to sum the values for job1 week wise where week starts from Monday to Sunday. This is the code I have written so far.</p>
  
  <pre><code>DateTime minDate = datatable.AsEnumerable()
          .Min(r =&gt; DateTime.Parse(r.Field&lt;string&gt;("DATE")));
  
  DateTime startDate = minDate.Date.Date.AddDays(+((6 + minDate.DayOfWeek
                                                      - DayOfWeek.Monday) % 7));
  
  DateTime nextDate = startDate.AddDays(6);
  
  DateTime maxDate = datatable.AsEnumerable()
          .Max(r =&gt; DateTime.Parse(r.Field&lt;string&gt;("DATE")));
  
  while (nextDate &lt; maxDate)
  {
      var weekEmpGroups = datatable.AsEnumerable()
      .Select(r =&gt; new
      {
          Row = r,
          Employee = r.Field&lt;String&gt;("Employee"),
          Date = DateTime.Parse(r.Field&lt;string&gt;("DATE")) 
          // week = minDate.Date.Date.AddDays(+((6 + minDate.DayOfWeek
                                                   - DayOfWeek.Monday) % 7))
      })
      .GroupBy(x =&gt; x.Employee);
  
  DataTable dtWeeklyResults = new DataTable();
  dtWeeklyResults.Columns.Add("Employee", typeof(string));
  var dtf = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
  
  double weekCount = 0.0;
  string expression;
  DataRow[] foundRows;
  
  foreach (var empGroup in weekEmpGroups)
  {
      string employee = empGroup.Key;
      var newRow = dtWeeklyResults.Rows.Add();
      newRow["Employee"] = employee;                        
  
      expression = "Employee=" + employee + " AND Date Between " + startDate
                 + " And " + nextDate;
      foundRows = datatable.Select(expression);
  
      if (foundRows.Length &gt; 0)
      {
          // add values using linq
      }
  
  } 
  </code></pre>
  
  <p>Please suggest if this is correct way to do this and also how to add all values week wise? The result should look like this for Job1:</p>
  
  <pre><code>Employee  1/7-1/13    1/14-1/20    1/21-1/27    1/28-2/3  and so on...
  A        sum of values for this 7 days
  B
  C
  D
  </code></pre>
  
  <p>Can anybody suggest how to achieve this by LINQ?</p>