Skip to content

Instantly share code, notes, and snippets.

@smoak
Created February 23, 2012 19:25
Show Gist options
  • Save smoak/1894497 to your computer and use it in GitHub Desktop.
Save smoak/1894497 to your computer and use it in GitHub Desktop.
private struct Row
{
public int UserId;
public DateTime DateUtc;
}
List<Row> table = new List<Row>
{
new Row { UserId = 1, DateUtc = DateTime.Parse("2012-01-05 17:00:00.000") },
new Row { UserId = 1, DateUtc = DateTime.Parse("2012-01-26 17:00:00.000") }
};
var total = 0;
foreach (var row in table)
{
var row1 = row;
foreach (var otherRow in table.Where(r => r.UserId == row1.UserId))
{
if (row.DateUtc.Year == otherRow.DateUtc.Year && row.DateUtc.Day == otherRow.DateUtc.Day && Math.Abs(row.DateUtc.Minute - otherRow.DateUtc.Minute) >= 60)
{
total++;
}
if (row.DateUtc.Year == otherRow.DateUtc.Year && row.DateUtc.Day != otherRow.DateUtc.Day)
{
total++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment