Thursday, March 18, 2010

Tolerance for DateTime comparison

By default, C# compares DateTime instances with a tolerance of 100 ns. Recently i ran into a situation where i needed to customize the tolerance level. C# doesnt provide any overloaded method operation to do so, but we could do ourself very easily.

if((dateTime1 - dateTime2).Duration() <>

This ensures a tolerance of 10 seconds.This can altered to do any tolerance level that we require.