AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

Linq The sum of hourly data?

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

Answers (2)

Petko Petkov
Petko Petkov

Reputation: 750

myCollection.GroupBy(x => x.date.Date).Select(x => new { Date= x.Key, Total = x.Sum(y => y.value) });

Upvotes: 3

Asif Mushtaq
Asif Mushtaq

Reputation: 13150

I dont say write codes for me

You can do it through Linq using GroupBy and Sum().

Upvotes: 4

Related Questions