Question: Here is my code:

```
private void textBox1_TextChanged(object sender, EventArgs e)
{
     DateTime myDate = DateTime.ParseExact(textBox1.Text, "yyyy-MM-dd H:m:s",
     System.Globalization.CultureInfo.InvariantCulture);

     TimeChangedHandler(myDate);
} 

```

If I delete 1 number from hours then it works fine, but if I delete both numbers e.x. I want to change from 11 to 22 then it crashes. So how do I make the form `"yyyy-MM-dd H:m:s"` work for all cases? Thanks!

Answer: 
You may benefit from using DateTime.TryParse method to check what of two formats your date is :

```
private void textBox1_TextChanged(object sender, EventArgs e)
{
     DateTime myDate = default(DateTime);
     if(!DateTime.TryParseExact(textBox1.Text, "yyyy-MM-dd H:m:s",
     System.Globalization.CultureInfo.InvariantCulture, out myDate))
       DateTime.TryParseExact(textBox1.Text, "yyyy-MM-dd HH:mm:ss",
         System.Globalization.CultureInfo.InvariantCulture, out myDate)     

     if(myDate == default(DateTime)) return; // or
      // throw new ArgumentException("your text here");

     TimeChangedHandler(myDate);
} 

```
Since it is on `TextChanged` event handler, you may wanna try to add, a `try...catch` handling during real time edits.

```
try
{
    DateTime myDate = DateTime.ParseExact(textBox1.Text, "yyyy-MM-dd H:m:s",
    System.Globalization.CultureInfo.InvariantCulture);

    TimeChangedHandler(myDate);
}catch( Exception ex )
{
    //Catch exception
}

```

Although a better solution would be placing it on a different event. Does the flexible edit means real time editing? If it is, changing the text from 11 to 22 during that time may cause the format to change, so the `ParseExact` would be better be placed on different event.