I am trying to write a simple LINQ query in which DateTime is compared to get the results. My requirement is that the DateTime has to be compared only till milliseconds and hence I have to apply formatter. The query is as follows
var availableValues = from value in AvailableValues
where DateTime.Compare(DateTime.ParseExact(value.Time.ToString("dd/MM/yyyy HH:mm:ss.fff"), "dd/MM/yyyy HH:mm:ss.fff", System.Globalization.CultureInfo.CurrentCulture),
DateTime.ParseExact(currentTime.ToString("dd/MM/yyyy HH:mm:ss.fff"), "dd/MM/yyyy HH:mm:ss.fff", System.Globalization.CultureInfo.CurrentCulture)) == 0
select value;
AvailableValues
is huge collection and the above query is causing a perfomance hit.
It would be of great help if someone could suggest me a better way to achieve the expected result.