Problems in using System.Convert.ToDateTime(string) method. Please help me.

Hi all,

I have a string s="10/29/2006" (in mm/dd/yyyy format)

I want to convert this string into a datetime value. I used the method

convert.ToDateTime(s)

But I am getting the error "string was not recognised as a valid datetime". Please help me out.



Answer this question

Problems in using System.Convert.ToDateTime(string) method. Please help me.

  • gr8mind

    it should be ok.

    have you tried to use TryParse in .NET 2.0 and see if it works

    DateTime theOutputResult = new DateTime();

    if (DateTime.TryParse("string", out theOutputResult))

    {

    //datetime parsed. value in "theOutputResult"

    }

    you could also try using ParseExact.

    http://msdn2.microsoft.com/en-us/library/w2sa9yss.aspx



  • techuser08

    When converting string into date you should always use ParseExact method of DateTime class.

  • Problems in using System.Convert.ToDateTime(string) method. Please help me.