How to compare HH:MM in C#
<p>Hi I have to compare HH:MM(hour and minutes). How can i do so?</p>

<pre><code>var t1 = DateTime.Now.ToString("HH:mm");
var t2 = "20:03";
var res =result(t1, t2);

public int result(string t1, string t2)
        {
            int i = -1;

            int hr1 = Convert.ToInt32(t1.Split(':')[0]);
            int hr2 = Convert.ToInt32(t2.Split(':')[0]);

            int min1 = Convert.ToInt32(t1.Split(':')[1]);
            int min2 = Convert.ToInt32(t2.Split(':')[1]);

            if (hr2 &gt;= hr1)
            {
                if (min2 &gt;= min1)
                {
                    i = 1;
                }
            }

            return i;
        }
</code></pre>

<p>But it is not correct.. it is not taking care of all conditions.. how to make it perfect. Or is there any built in function that does this with thsi input only(I checked but no answer).</p>

<p>Thanks in advance</p>
