Calculating the difference between 2 times, and then compare the difference to see if it is less than 5 minutes

.net, c#

Solution

Just use the subtraction operator, and use the `Duration` method to get the absolute value

DateTime dt1 = ...;
DateTime dt2 = ...;

TimeSpan diff = (dt2 - dt1).Duration();

if (diff.TotalMinutes < 5)
{
    // do something
}

Problem

I want to calculate the difference between two times and then compare difference is less than 5 MIN.. Please note I want difference in min. using c#.net

Original source