I am trying to validate two date of birth text box fields. If the member does not enter in these two boxes an error message will popped out like "pls enter valid date format"
When trying to save without entering the textbox values, it was showing error like this at Datetime DV
.
String was not recognized as a valid DateTime.
private void btnCTimetablessave_Click(object sender, EventArgs e)
{
string dob = tbStartDate.Text;
DateTime dv;
if (!DateTime.TryParse(dob, out dv))
{
MessageBox.Show("pls enter a valid start date");
return;
}
string format1 = dv.ToString("yyyy-MM-dd");
string dob2 = tbEndDate.Text;
DateTime dt2;
if (!DateTime.TryParse(dob2, out dt2))
{
MessageBox.Show("pls enter valid end date");
return;
}
string format2 = dt2.ToString("yyyy-MM-dd");
Still it was showing error at datetime Dv
"String was not recognized as a valid DateTime" ;