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
To get the time difference in a single time unit (hours ,minutes or seconds), you can perform the following calculations. Total minutes between two times: To calculate the minutes between two times, multiply the time difference by 1440, which is the number of minutes in one day (24 hours * 60 minutes = 1440).
The following formula can help us compute the difference between two date times in days, hours, and minutes if we have two lists of dates and times. We need to type the following formula into a blank cell: =INT(B2-A2)&" days "&TEXT(B2-A2,"h"" hours ""m"" minutes """)
Discussion: If you'd like to calculate the difference between the timestamps in seconds, multiply the decimal difference in days by the number of seconds in a day, which equals 24 * 60 * 60 = 86400 , or the product of the number of hours in a day, the number of minutes in an hour, and the number of seconds in a minute.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With