Q:

Comparing DateTimes in C# producing unexpected results

Im trying to compare if a runtime variable is within now and one minute from now. Here is the code:
if (RunTime.ToUniversalTime() >= now.ToUniversalTime() && 
    RunTime.ToUniversalTime() < now.AddMinutes(1).ToUniversalTime())
{
    //Do Stuff 
}

However this evaluates to true a minute before I would expect. for instance if I have my runtime as 9:30 it evaluates to true from 9:29 to 9:30 not 9:30 - 9:31. What Am I missing here? The way I understand the code is that it would evaluate to true when runtime is greater than or equal to now and less than now plus one minute. 

A:

RunTime.ToUniversalTime() >= now.ToUniversalTime() && 
RunTime.ToUniversalTime() < now.AddMinutes(1).ToUniversalTime()

Let us rewrite this condition:
now.ToUniversalTime() <= RunTime.ToUniversalTime() &&
now.ToUniversalTime() > RunTime.AddMinutes(-1).ToUniversalTime()

So when RunTime is 9:30, then condition should be true from RunTime.AddMinutes(-1) (9:29) exclusive to RunTime (9:30) inclusive. Just like you say it is in your post.
If you what that condition be true from 9:30 to 9:31, than you should use different condition:
now.ToUniversalTime() >= RunTime.ToUniversalTime() &&
now.ToUniversalTime() < RunTime.AddMinutes(1).ToUniversalTime()

