SQL Server 2008 GET DATETIMEOFFSET according to machine settings

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:45:00

问题


On SQL Server 2008 R2, I have following T-SQL code:

SELECT CAST(GETDATE() AS DATETIMEOFFSET);

This gives me the result as below:

2011-12-26 10:21:13.7970000 +00:00

But the result is what I wanted to be. It should be this:

2011-12-26 10:21:13.7970000 +02:00

Here is my machine's Date and Time Settings:

The same thing happens while I am inserting a value:

DECLARE @foo AS TABLE(
    fooDate DATETIMEOFFSET
);

INSERT @foo VALUES(GETDATE());

SELECT * FROM @foo;

This gets me the same wrong result (at least wrong for my needs).

What am I missing here?


回答1:


Try this

SELECT SYSDATETIMEOFFSET();

GETDATE() function has no any timezone information



来源:https://stackoverflow.com/questions/8634104/sql-server-2008-get-datetimeoffset-according-to-machine-settings

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