Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LINQ .Distinct() with DateTime - Selecting only the first instance of a date

I use EF and LINQ in my MVC 3 web app.

I have a query like this

var dates = timetableEvents.GroupBy(x => x.DateTimeStart).Distinct();

x.DateTimeStart are date in this format:

23/01/2013 12:47:13
23/01/2013 14:00:10
23/01/2013 16:15:00
24/01/2013 02:05:00
24/01/2013 04:55:05
25/01/2013 06:00:00

I need to have the filter which select only the first instance of a date.

How to do it?

23/01/2013
24/01/2013
25/01/2013
like image 435
GibboK Avatar asked Dec 01 '22 22:12

GibboK


1 Answers

Can you try

  var dates = timetableEvents.GroupBy(x => x.DateTimeStart.Date).Distinct();
like image 60
Junaid Avatar answered Dec 05 '22 08:12

Junaid