Skip to content

Instantly share code, notes, and snippets.

@smoak
Created March 1, 2012 00:17
Show Gist options
  • Save smoak/1945982 to your computer and use it in GitHub Desktop.
Save smoak/1945982 to your computer and use it in GitHub Desktop.
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