String was not recognized as a valid DateTime “ format dd/MM/yyyy”

前端 未结 13 1127
一整个雨季
一整个雨季 2020-11-22 05:30

I am trying to convert my string formatted value to date type with format dd/MM/yyyy.

this.Text=\"22/11/2009\";

DateTime date = DateTime.Parse(         


        
13条回答
  •  伪装坚强ぢ
    2020-11-22 05:59

    Just like someone above said you can send it as a string parameter but it must have this format: '20130121' for example and you can convert it to that format taking it directly from the control. So you'll get it for example from a textbox like:

    date = datetextbox.text; // date is going to be something like: "2013-01-21 12:00:00am"
    

    to convert it to: '20130121' you use:

    date = date.Substring(6, 4) + date.Substring(3, 2) + date.Substring(0, 2);
    

    so that SQL can convert it and put it into your database.

提交回复
热议问题