I need to validate the In time and out time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakthivelm
    New Member
    • Oct 2016
    • 2

    I need to validate the In time and out time

    I have two text boxes In time and out time , i need to validate out time should not less than 2 hours of in time
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Code:
                try
                {
                    DateTime intime;
                    DateTime.TryParse(textBox1.Text, out intime);
                    DateTime outtime;
                    DateTime.TryParse(textBox2.Text, out outtime);
                    TimeSpan t = (outtime - intime).Duration();
                    MessageBox.Show("The difference between " + intime.ToShortTimeString() +
                        " and " + outtime.ToShortTimeString() + " is: " + t.TotalSeconds + " seconds");
    
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Invalid time " + ex.Message);
                }

    Comment

    Working...