Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't found the Linq solution but I can offer you a programmatic one. Note that I did this using full DateTime representation because of parsing instead of your that doesn't have year. Check the code:</p> <pre><code> //DataTable initialisation dt = new DataTable(); dt.Columns.Add("Column1"); dt.Columns.Add("Column2"); dt.Columns.Add("Column3"); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 10:10"), 1, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 10:20"), 1, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:05"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:06"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:07"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:08"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:09"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:10"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:11"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:12"), 2, 0.1 }); dt.Rows.Add(new object[] { DateTime.Parse("6/10/2012 11:13"), 2, 0.1 }); //Method that groups data void GroupByDate() { DateTime startDate = DateTime.Parse(dt.Rows[0].ItemArray[0].ToString()); DateTime endDate = DateTime.Parse(dt.Rows[dt.Rows.Count - 1].ItemArray[0].ToString()); StringBuilder sb = new StringBuilder(); int rowIndex = 0; for (DateTime d = startDate.AddMinutes(-(startDate.Minute - 1) % 10); rowIndex &lt; dt.Rows.Count &amp;&amp; d &lt; endDate.AddMinutes(10 - endDate.Minute % 10); d = d.AddMinutes(10)) { double sum = 0; DateTime lastDateInSequence = new DateTime(); for (DateTime md = d;rowIndex &lt; dt.Rows.Count &amp;&amp; md &lt; d.AddMinutes(10); md = md.AddMinutes(1)) { DateTime inbetween = DateTime.Parse(dt.Rows[rowIndex].ItemArray[0].ToString()); if ( inbetween == md) { sum += double.Parse(dt.Rows[rowIndex].ItemArray[2].ToString()); lastDateInSequence = md; rowIndex++; } } if (sum &gt; 0.0) { // you can add this results to the new DataTable like dt1.Rows.Add(lastDateInSequence.ToString("dd/MM hh:mm"), dt.Rows[rowIndex - 1].ItemArray[1], sum); sb.Append(lastDateInSequence.ToString("dd/MM hh:mm") + " " + dt.Rows[rowIndex - 1].ItemArray[1].ToString() + " " + sum.ToString() + Environment.NewLine); } } MessageBox.Show(sb.ToString()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload