ผู้สอบถาม
T-SQL to convert Datetime and DatetimeOffset to Zulu Format

คำถาม
-
How to convert datetime and datetimeoffset to zulu format in Sql server 2014 and above
How does the function SYSDATETIMEOFFSET() works - Does it calculate the offset of the server in which SQL Server is installed w.r.t to UTC timezone . Or how does it works internally
14 สิงหาคม 2563 15:15
ตอบทั้งหมด
-
Hi
Do you need to change time zone offset
DECLARE @CurrentDateTime DATETIME2; SET @CurrentDateTime = Getdate(); SELECT Todatetimeoffset (@CurrentDateTime, '+08:00') AS CURRENT_DATE_TIME_OFFSET_CHANGE;
Thanks and regards
14 สิงหาคม 2563 15:51 -
It returns the server offset from UTC time.
See the examples:
14 สิงหาคม 2563 16:05 -
Thanks
How do we convert datetime/datetimeoffset to zulu format . Please suggest
16 สิงหาคม 2563 22:47 -
This should work
select convert(varchar(51), GETUTCDATE(),127)+'Z'
17 สิงหาคม 2563 0:48 -
Hi SubhadipRoy,
Please refer to below sql:
select DATEADD(hour,DATEDIFF (hour, GETDATE(), GETUTCDATE()),MyLocalDateTime) as GmtDateTime
I found a similar issue, you can refer to:SQL Convert to GMT DateTime
Best Regards
Echo
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- แก้ไขโดย Echo Liuz 17 สิงหาคม 2563 7:40
17 สิงหาคม 2563 7:39 -
This is more difficult than you think, if you are talking about converting past times to UTC time. You would have to know the offset on the date, including daylight savings time.
If you just want now in UTC, then use SYSUTCDATETIME: https://docs.microsoft.com/en-us/sql/t-sql/functions/sysutcdatetime-transact-sql?view=sql-server-ver15
- แก้ไขโดย Tom Phillips 17 สิงหาคม 2563 12:50
17 สิงหาคม 2563 12:50 -
Hi SubhadipRoy,
Has your problem been solved? If it is solved, please mark the point that you
think is correct as an answer. This can help others who encounter similar problems.
Best Regards
Echo""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.18 สิงหาคม 2563 5:56 -
How do we convert datetime/datetimeoffset to zulu format . Please suggest
select convert(varchar(51), GETUTCDATE(),127)+'Z' is not giving the expected value .
When using SELECT SYSDATETIMEOFFSET() and trying to convert to zulu format using the convert(varchar(51), GETUTCDATE(),127)+'Z'
offset value is not getting honoured
18 สิงหาคม 2563 16:39 -
If you just want the current UTC datetime as an offset, you just need to do this:
SELECT CAST(SYSUTCDATETIME() AS datetimeoffset)
18 สิงหาคม 2563 16:46 -
Hi SubhadipRoy,
This thread has lots of replies without any resolution.
If you want to get an answer, you need to provide a minimal reproducible example:
(1) DDL and sample data population, i.e. CREATE table(s) plus INSERT, T-SQL statements.
(2) What you need to do, i.e. logic.
(3) Desired output based on the sample data in #1 above.
(4) Your SQL Server version (SELECT @@version;)- แก้ไขโดย Yitzhak Khabinsky 18 สิงหาคม 2563 16:49
18 สิงหาคม 2563 16:48 -
Did you ever tell us what Zulu format is?
Can you give us some examples of input and the expected result?
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
18 สิงหาคม 2563 21:15 -
How do we convert datetime/datetimeoffset to zulu format .
Zulu isn't a "format", it's the military naming for UTC +0 timezone, nothing else and you got already example for UTC.
https://www.timeanddate.com/time/zones/z
Olaf Helper
[ Blog] [ Xing] [ MVP]- เสนอเป็นคำตอบโดย Laxmidhar sahoo 23 สิงหาคม 2563 14:28
19 สิงหาคม 2563 5:45 -
Hi SubhadipRoy,
Do you have any updates?
Has your problem been solved? If it is solved, please mark the point that you
think is helpful as an answer. This can help others who encounter similar problems.Best Regards
Echo
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.- แก้ไขโดย Echo Liuz 20 สิงหาคม 2563 5:25
20 สิงหาคม 2563 5:25