I\'m doing DateTime comparison but I don\'t want to do comparison at second, millisecond and ticks level. What\'s the most elegant way?
If I simply compare the DateT
I've written this to help myself:
internal class ImpreciseCompareDate : IComparer
{
private readonly double _Tolerance;
public ImpreciseCompareDate(double MillisecondsTolerance)
{
_Tolerance = MillisecondsTolerance;
}
public int Compare(DateTime x, DateTime y)
{
return Math.Abs((x - y).TotalMilliseconds) < _Tolerance ? 0 : x.CompareTo(y);
}
}
Tolerance can be set to (10d/3d) to account for SQL servers 1/300th of a ms. If tolerance is exceeded, delegate to default comparer.