SQL Server Timezone Change

£可爱£侵袭症+ 提交于 2021-01-28 08:13:27

问题


I have 2 databases on the same SQL Server. Is it possible to have one in PST and the other in EST?


回答1:


No, The date/time is derived from the operating system of the computer on which the instance of SQL Server is running.

You could however have a custom UDF that you would call instead of getdate() and then do the timezone change in that UDF. You can also assign default values to columns with something like this

CREATE TABLE Test (Val DATETIME DEFAULT  dateadd(hh,-3,GETDATE()))

Now when you do an insert it will use the default

INSERT test DEFAULT VALUES

SELECT * FROM test

....this of course won't work on updates and also someone could update that value

If you want to use GMT then use GETUTCDATE

SELECT GETUTCDATE()


来源:https://stackoverflow.com/questions/9982400/sql-server-timezone-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!