Checking whether Math.Abs(diff.TotalMinutes) == 0 , no - checks to see if they are exactly the same.
Are you trying to check if they have the same minute, or are they less than a minute? For the first use:
where RoundToMinute(dateTime1) == RoundToMinute(dateTime2)
declaring:
public static DateTime RoundToMinute(DateTime time) { return new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0, time.Kind); }
For the second use:
where Math.Abs((dateTime1 - dateTime2).TotalMinutes) < 1
You must consider that you want the result if it is local and one in UTC, by the way ...
Please note that LINQ is not specified here - it is assumed that you are using LINQ for objects. If you use LINQ to SQL, then obviously you cannot use local methods, and we will have to look again ...
EDIT: I am still very unclear in your question. If you need them to be exactly the same date / time, this is easy (not to mention a possible local and UTC problem):
where dateTime1 == dateTime2
However, the question arises as to why you mention "minimal accuracy" in the title of the question or "use to the smallest accuracy" in the body of the question.
Jon skeet
source share