Checking if a string is in date format

feurich

Centurion
Joined
Oct 21, 2003
Messages
170
Location
Holland
Hi there,

I am trying to check if a date string 12-12-2005 is in date format in C#. But I can't seem to find a way of doing it.
I just get a string like 12-12-2005 and I want to check if this string is in the regional date format.

Thanks,

Feurich
 
[csharp]
private void button1_Click(object sender, System.EventArgs e)
{
if (CheckIfDate(textBox1.Text))
{
MessageBox.Show("Deze string voldoet aan het datum formaat");
}
else
{
MessageBox.Show("Deze string voldoet niet aan het datum formaat");
}
}

private bool CheckIfDate(string Value)
{
try
{
System.DateTime odate = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990,5,6)).ConvertFrom(textBox1.Text));
textBox2.Text = odate.Date.ToString();
return true;
}
catch
{
return false;

}

[/csharp]
 
Back
Top