What’s the best way to do it?
This is how I’ll usually do it:
DateTime newDate;
try
{
newDate = DateTime.Parse(Textbox.Text);
}
catch
{
//isn't a datetime
return;
}
//do stuff with the date
But something tells me that that is a bit wrong. Any ideas?
Use the DateTime.TryParse method instead of using your own try/catch blocks.