How to store date in dd-mon-yyyy format in SQL Server?

后端 未结 1 493
梦谈多话
梦谈多话 2021-01-29 02:27

The below works for displaying the date, but when writing to the database [in a datetime column] it seems to be getting converted to the default format.

REPLACE(         


        
1条回答
  •  孤街浪徒
    2021-01-29 02:37

    Date/time values in the database are stored in a binary format. They are not stored as strings. This is the right way to store them.

    If you want to fetch the data in a particular format, then use the formula when you retrieve them. Or, you can add a computed column:

    alter table t
        add date_field_ddmonyyyy as (REPLACE(CONVERT(VARCHAR(11), CONVERT(DATETIME,DATE_FIELD), 106), ' ', '-'));
    

    0 讨论(0)
提交回复
热议问题