I have two datetimes, one from a timestamp, and another I'm generating in code. I need to test their equality, and would love to do it without too many expressions. Here's an example of my two dates:
DateTime expireTimeStampUTC =
DateTime.Parse(UTCValueFromDatabase));
DateTime expectedExpireTime =
DateTime.UtcNow.AddHours(NumberOfExpectedHoursInConfig);
This is too high precision of a test:
if (expireTimeStampUTC.Equals(expectedExpireTime)){}
I don't care if they're exact to the second, just the hour.
Could it possibly be the best solution to do something compound like this:
if (expireTimeStampUTC.Date.Equals(expectedExpireTime.Date))
{
if (!expireTimeStampUTC.Hour.Equals(expectedExpireTime.Hour))
{
pass = false;
}
}
I'm not the most experienced with C#... is there some elegent way to do this?