How to Handle Time on a Form c #? What would be the code to save and validate?
Attached Graphic Example Image of what I want to do Example:
Greetings
You can use the DateTimePicker
component, and place the property
format = Time
, then to validate the dates you can do something like this
if (DateTime.Parse("01/01/1900 " + dateTimePicker1.Text) > DateTime.Parse("01/01/1900 " + dateTimePicker2.Text))
{
MessageBox.Show("Las 1 hora es mayor", "..::Aviso del Sistema::..");
}
else if (DateTime.Parse("01/01/1900 " + dateTimePicker1.Text) == DateTime.Parse("01/01/1900 " + dateTimePicker2.Text))
{
MessageBox.Show("Las horas son iguales", "..::Aviso del Sistema::..");
}
else if (DateTime.Parse("01/01/1900 " + dateTimePicker1.Text) < DateTime.Parse("01/01/1900 " + dateTimePicker2.Text))
{
MessageBox.Show("Las 2 hora es mayor", "..::Aviso del Sistema::..");
}
where dateTimePicker1 and dateTimePicker2 are the components you use in the form.