Is there a method in C# which can compare dates like the SQL DateDiff method, including time part argument?
For example I have two dates:
DateTime early = "2013.02.01 07:31:15";
DateTime soon = "2013.02.01 23:48:35";
if (Compare(early, soon, DAY) == true)
{
//I want to be here
}
I want to get info that these two objects are equal in year, month and day; the rest is not important to me.
You can use
DateTime.Date:if you want accurancy of hours:
But, with this solution you will have “12/03/1857 23:59” != “13/03/1857 00:00”. If you want to check their “distance”:
.Duration()gets the “absolute” value of the time span (becauseearly.Substract(soon)can be “positive” or “negative”).