I want to compare two dateTime.
Ex:
date1 = 13/01/2004 12:20:00
date2 = 13/01/2004 12:35:00
result = Compare(date2-date1);
O/P : 15 Minutes
To compare, you can simply use the <
operator: date1 < date2
.
If you want to compare with a given resolution, try date1.TotalMinutes == date2.TotalMinutes
(this compared for the same minute).
If you want to know if the difference is within a certain time span, use this:
System.TimeSpan dt = date2.Subtract(date1);
if (dt.TotalMinutes < 15) //...
Try this:
TimeSpan diff = date2.Subtract(date1);
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