Change default date time format on a single database in SQL Server

前端 未结 8 1142
孤城傲影
孤城傲影 2020-11-30 05:16

I need to change the date format from US (mm/dd/YYYY) to UK (dd/mm/YYYY) on a single database on a SQL server machine.

How can this be done?

I\'ve seen state

相关标签:
8条回答
  • 2020-11-30 05:20

    If this really is a QA issue and you can't change the code. Setup a new server instance on the machine and setup the language as "British English"

    0 讨论(0)
  • 2020-11-30 05:20

    You do realize that format has nothing to do with how SQL Server stores datetime, right?

    You can use set dateformat for each session. There is no setting for database only.

    If you use parameters for data insert or update or where filtering you won't have any problems with that.

    0 讨论(0)
  • 2020-11-30 05:20

    For SQL Server 2008 run:

    EXEC sp_defaultlanguage 'username', 'british'
    
    0 讨论(0)
  • 2020-11-30 05:29

    Use:

    select * from mytest
    EXEC sp_rename 'mytest.eid', 'id', 'COLUMN'
    alter table mytest add id int not null identity(1,1)
    update mytset set eid=id
    ALTER TABLE mytest DROP COLUMN eid
    
    ALTER TABLE [dbo].[yourtablename] ADD DEFAULT (getdate()) FOR [yourfieldname]
    

    It's working 100%.

    0 讨论(0)
  • 2020-11-30 05:34

    You can only change the language on the whole server, not individual databases. However if you need to support the UK you can run the following command before all inputs and outputs:

    set language 'british english'
    

    Or if you are having issues entering datatimes from your application you might want to consider a universal input type such as

    1-Dec-2008

    0 讨论(0)
  • 2020-11-30 05:35

    You could use SET DATEFORMAT, like in this example

    declare @dates table (orig varchar(50) ,parsed datetime)
    
    SET DATEFORMAT ydm;
    
    insert into @dates
    select '2008-09-01','2008-09-01'
    
    SET DATEFORMAT ymd;
    insert into @dates
    select '2008-09-01','2008-09-01'
    
    select * from @dates
    

    You would need to specify the dateformat in the code when you parse your XML data

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