[Solved] Group dates in a List


Based on the data you’ve provided, here’s one way to do it. Please note, that this code is written and executed in LinqPad, so .Dump() only works there:

var source = new List<KeyValuePair<string, string>> {
    new KeyValuePair<string, string>( "datetime", "01/23/2017 01:10:30") ,
    new KeyValuePair<string, string>( "datetime", "01/23/2017 10:00:00" ),
    new KeyValuePair<string, string>( "datetime", "01/23/2017 11:23:15" ),
    new KeyValuePair<string, string>( "datetime", "01/20/2017 07:13:20" ),
    new KeyValuePair<string, string>( "datetime", "01/20/2017 08:20:11" ),
    new KeyValuePair<string, string>( "datetime", "01/21/2017 07:28:29" )
};

var list = source.Select (s => s.Value)
    .GroupBy (s => DateTime.ParseExact(s, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture).Date)
    .ToList();

list.Dump();

Output:

enter image description here

0

solved Group dates in a List>