I’m thinking that I should use database select, groupby queries but not sure how to do this. Can someone please help me to create that output data table?
Tried to create linq but it’s only calculating seconds, needs some modification.
Check once and let me know how exactly you need data in Total Time.
Please mention example.
(From r In dtInput.AsEnumerable
Group r By k = r(“ReleaseName”).tostring Into grp = Group
Let sumstart = grp.Sum(Function (x) x.Field(Of Date)(“StartTime”).TimeOfDay.TotalSeconds)
Let sumend = grp.Sum(Function (x) x.Field(Of Date)(“EndTime”).TimeOfDay.TotalSeconds)
Let subtract = CInt(sumstart) - CInt(sumend)
Let ra = New Object() {grp(0)(“ReleaseName”),subtract,grp.Count}
Select dtOutput.Rows.Add(ra)).CopyToDataTable test.xaml (7.3 KB)
I want total time as a timespan HH:mm:ss. That too endtime-starttime should be calculated for every row in the group and then these results should be added.
I’ve one more doubt of this substraction. I feel that @ermanoj3101 query adds all start-times in a group and adds all end-times in a group and then calculates difference of these sums
I need to calculate end time-start time for each row in the group and then sum these values.
(From row In inputDT
Group row By rn = row("ReleaseName").ToString
Into grp = Group
Let dur = grp.Sum(Function (x) DateTime.Parse(x("EndTime").ToString).TimeOfDay.TotalSeconds -DateTime.Parse(x("StartTime").ToString).TimeOfDay.TotalSeconds)
Let ra = New Object() {grp(0)("ReleaseName"),TimeSpan.FromSeconds(dur),grp.Count}
Select outDT.Rows.Add(ra)).CopyToDataTable