Windows Phone Developers

Saturday, March 17, 2012

C# IsDate Function / How to check valid date using C# function

IsDate Function in .NET

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 Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment