Reputation: 15866
There are hourly data is captured in my table. I want to sum of these data for a day. For example
this is my table data
| date | value |
| 12.03.2010 01.pm | 10 |
| 12.03.2010 02.pm | 20 |
| 12.03.2010 03.pm | 15 |
| 13.03.2010 04.pm | 15 |
| 13.03.2010 05.pm | 25 |
| 13.03.2010 08.pm | 35 |
And I want to get sum of values in a day.
12.03.2010 total_usage = 45
12.03.2010 total_usage = 75
How Can I do this. How can I get sum of hourly data in a day.
Thanks.
Upvotes: 1
Views: 264
Reputation: 750
myCollection.GroupBy(x => x.date.Date).Select(x => new { Date= x.Key, Total = x.Sum(y => y.value) });
Upvotes: 3
Reputation: 13150
I dont say write codes for me
You can do it through Linq
using GroupBy
and Sum()
.
Upvotes: 4