efficient way to compare datetime
<p>Am trying to execute the formula like below,just wondering what's the efficient method to do,</p>

<p>Below is the formula to calculate </p>

<p><strong>result=  min(max(dtmealstart1,dtbkgstart),dtbkgend)</strong></p>

<pre><code>dtmealstart1= 11/02/13 8AM
dtbkgstart=11/02/13 9AM
dtbkgend=11/02/13 17.00 (5PM)
result=min(max(11/02/13 8AM,11/02/13 9AM),11/02/13 17.00 )
result=11/02/13 9AM   
</code></pre>

<p>I just wrote this piece of code in c# to do the above logic but am just wondering is there any best way to do</p>

<pre><code>int result = DateTime.Compare(dtmealStart1, dtBkgStart);
DateTime break1;
if (result &lt; 0)
{
    break1 = dtBkgStart;
}
else
{
    break1 = dtmealStart1;
}
int result1 = DateTime.Compare(break1, dtBkgEnd);
DateTime mealstart1;
if(result1&lt;0)
{
    mealstart1 = break1;
}
else
{
    mealstart1 = dtBkgEnd;
}
</code></pre>

<p>my <code>mealstart1</code> value also bring it back <code>11/02/13 9AM</code></p>
