DateTime Comparison Precision

What about using a timespan.

if (Math.Truncate((A - B).TotalMinutes) == 0)
{
    //There is less than one minute between them
}

Probably not the most elegant way, but it allows for cases which are one second apart and yet have different days/hours/minutes parts such as going over midnight.

Edit: it occured to me that the truncate is unecessary…

if (Math.Abs((A - B).TotalMinutes) < 1)
{
    //There is less than one minute between them
}

Personally I think this is more elegant…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)