Skip to content

Problem in using the method Convert.ToDateTime(string) Please help me.

Ravinder Reddy

Asked Nov 22, 2006, 10:27 PM EST2 answers
Share
LinkedInX
Hi All,

                I have a string s that is "10/29/2006". I want to convert this string to datetime format.

 used the method

                          DateTime dt=System.Convert.ToDateTime(s);



                                 But it is giving an error "string was not recognised as a valid datetime. Please help me out.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi, It's a very simple code, I don't know why you are getting an error for this. See the code below --- string s = "10/29/2006"; DateTime dt = Convert.ToDateTime(s);
    0
  • 0

    Use this code
    DateTime.Parse(txtStartDate.Text).ToString("yyyy/MM/dd")

    also i suggest you to chage ur system datetime settings to the above mentioned format

    0