SQL Server - 将日期字段转换为UTC [英] SQL Server - Convert date field to UTC
本文介绍了SQL Server - 将日期字段转换为UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近更新了我的系统,以UTC作为本地时间存储的日期/时间。
I have recently updated my system to record date/times as UTC as previously they were storing as local time.
我现在需要转换所有本地存储日期/次到UTC。我想知道是否有内置函数,类似于.NET的 ConvertTime
方法?
I now need to convert all the local stored date/times to UTC. I was wondering if there is any built in function, similar to .NET's ConvertTime
method?
我正在尝试
任何建议?
推荐答案
如果他们都是本地的,那么这里是偏移量:
If they're all local to you, then here's the offset:
SELECT GETDATE() AS CurrentTime, GETUTCDATE() AS UTCTime
,您应该可以使用以下方式更新所有数据:
and you should be able to update all the data using:
UPDATE SomeTable
SET DateTimeStamp = DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()), DateTimeStamp)
这是否工作,或者我是否还有另一个角度出现这个问题?
Would that work, or am I missing another angle of this problem?
这篇关于SQL Server - 将日期字段转换为UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文