Could someone demonstrate how you could implement DateTime.TryParse into my current code which takes in intergers. For example a 24 hour time format 23:00
private void textBox2_Validating(object sender, CancelEventArgs e)
{
int numberEntered;
if (int.TryParse(textBox2.Text, out numberEntered))
{
if (numberEntered < 1 || numberEntered > 28)
{
MessageBox.Show("");
textBox2.Text = 5.ToString();
}
}
else
{
MessageBox.Show("");
textBox2.Text = 5.ToString();
}
}
This should do what you want:
I would recommend doing some reading up on the various parameters available for DateTime.TryParseExact, and choosing the ones that match your situation with care. Also have a look at the values of actual DataTime objects that get generated by this parse, since they will have a Date part as well – if you use this data later on (particularly for comparing these times) these details could prove important.