Set DateTime format

后端 未结 6 1253
萌比男神i
萌比男神i 2020-12-03 22:44

I have the following code -

DateTime timeStamp;

timeStamp = System.Convert.ToDateTime(y.InnerText);

Where y.InnerText is

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 23:11

    Basically Date does not have a format. If the database parameter/field is Datetime type you should be fine passing as a Date type. It is not a good idea to pass date as a string.

    However, if that something you have to deal with, then you better pass the Date in a none culture specific date format (ISO8601 or ISO) in a parameterised query. Otherwise you could have problems with database servers in different culture settings.

    For example, for sql server, it is safe (in conversion) to pass date time in ISO8601 as;

    'yyyy-mm-ddThh:mi:ss.mmm' //(no spaces)
    

提交回复
热议问题