If you want to check if the given entry (string) is a valid date you could have used Microsoft.VisualBasic.IsDate Function in .NET. This function is available in VB.NET. For C# you can have a similar function
Here is a hint how to create that
private void IsDateExample() { //string s1 = DateTime.Now.ToString(); bool bSuccess = false; DateTime d1; s1 = "17-Mar-20112"; bSuccess = DateTime.TryParse(s1, out d1); if (bSuccess == true) { Console.WriteLine(d1.ToString()); } else { Console.WriteLine("Not a date at all"); } }
The function uses DateTime.TryParse to validate the given string
No comments:
Post a Comment