Saving Dates in SQLServer

后端 未结 7 1359
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 00:16

I have a legacy application where the input is a date string, i.e.:

06/12/2009

The format of the input is always a string, and i

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-05 00:37

    Keep in mind that DATA is not its PRESENTATION. In this case that DATA is a DATE or DATETIME, regardless of how you show them.
    As for inserting/updating/comparing datetime values, I quote the BOL:

    When specifying dates in comparisons or for input to INSERT or UPDATE statements, use constants that are interpreted the same for all language settings: ADO, OLE DB, and ODBC applications should use the ODBC timestamp, date, and time escape clauses of:
    { ts 'yyyy-mm-dd hh:mm:ss[.fff] '} such as: { ts '1998-09-24 10:02:20' }
    { d 'yyyy-mm-dd'} such as: { d '1998-09-24' }
    { t 'hh:mm:ss'} such as: { t '10:02:20'}

    I can assure you that, if you use this formats they will always work, regardless of the locale of you server

提交回复
热议问题