问题
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