Heisenberg
Heisenberg

Reputation: 87

How to group by date leaving hour?

So I have a list of matches which have a property called Schedule, this property is a DateTime and can contains the following values:

id | Schedule
 1    2018-08-11 14:00 
 2    2018-08-11 20:00
 3    2018-08-12 15:00

now I want group all the date available in this list, so I tried:

var dates = matches.GroupBy(c => c.Schedule); 

the problem is that I get all the dates, but I should get as result: 1, 3, because the date 1 and 2 are equal (only the hour change and this shouldn't matter).

Upvotes: 0

Views: 43

Answers (1)

MistyK
MistyK

Reputation: 6222

Try using property Date

var dates = matches.GroupBy(c => c.Schedule.Date); 

Upvotes: 6

Related Questions