Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Trust the Universe
Posted

[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]

Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...