Created
March 1, 2012 00:17
-
-
Save smoak/1945982 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
public DateTime Date; | |
public string Name; | |
} | |
var list = new List<MyClass> { | |
new MyClass { Date = new DateTime(2012, 02, 01), Name = "Week 1" }, | |
new MyClass { Date = new DateTime(2012, 02, 06), Name = "Week 2" }, | |
new MyClass { Date = new DateTime(2012, 02, 13), Name = "Week 3" }, | |
}; | |
var weekTicks = (Int64)10000000 * 7 * 24 * 60 * 60; | |
var groupedByWeek = list.GroupBy(s => s.Date.Ticks / weekTicks).ToDictionary(s => new DateTime(s.Key * WeekTicks), s => s.Count());; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment