Comparing time

The snippet is used to compare the time

//defining 2 string time objects.
string t1 = DateTime.Parse("12:40").ToString("t");
string t2 = DateTime.Parse("5:07").ToString("t");
//parsing the strings to time and then comparing.
if (DateTime.Parse(t1) > DateTime.Parse(t2))

Response.Write(t1.ToString() + "is greater than " + t2.ToString());
Response.Write(t2.ToString() + "is greater than" + t1.ToString());

The snippet defines two string time objects.The time is compared by converting string to date time and then using compare operators like <,> to compare the time.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: