Problems in using System.Convert.ToDateTime(string) method. Please help me.  
Author Message
K. Ravinder Reddy





PostPosted: Visual C# General, Problems in using System.Convert.ToDateTime(string) method. Please help me. Top

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.



Visual C#17  
 
 
ahmedilyas





PostPosted: Visual C# General, Problems in using System.Convert.ToDateTime(string) method. Please help me. Top

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



 
 
boban.s





PostPosted: Visual C# General, Problems in using System.Convert.ToDateTime(string) method. Please help me. Top

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