当我在我的时区没有遵守 DST 时确定当前 DST 状态 (SQL Server)
我正在从全国各地的许多不同服务器接收数据源,并且这些项目带有 GMT 时间戳。我知道每个位置的标准时间 GMT 偏移量,但我不确定哪些位置支持/遵守夏令时。通常,我只是检查我的当地时间,看看偏移量是多少,然后从那里开始 - 由于当前与 GMT 的偏移,我可以轻松确定当前是否观察到 DST) - 除了我的服务器位于亚利桑那州,那里是 DST没有观察到。因此,无论 DST 当前是否处于活动状态,我始终处于 GMT-7。
当我的本地服务器不更改时间时,是否有一种简单的方法可以确定是否遵守夏令时?如果需要的话,我什至可以编写一个 .NET SQL-CLR 组件来检查系统上的某些内容,但如果可能的话,我希望直接从 T-SQL 代码中执行此操作。
I'm receiving data feeds from a number of different servers across the country, and the items come in timestamped with GMT. I know the GMT offset for each of the locations for standard time, but I'm not sure which locations support/observe Daylight Time. Normally, I'd just check my local time to see what the offset is and then go from there - I could easily determine if DST is currently observed because of the current offset from GMT) - except that my server sits in Arizona, where DST is not observed. As a result, I'm always GMT-7, regardless of whether DST is currently active.
Is there an easy way to determine if DST is being observed when my local server doesn't change time? I could even write a .NET SQL-CLR component that checks something on the system if I need to, though I'd ideally like to do it directly from T-SQL code if that's possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,SQL Server 没有提供显式的 DST 标志或函数。
不过,今年 DST 生效后,您可以为每个服务器编译一个新的偏移列表
datediff(hh,getutcdate(),getdate())
,并将其与当前的标准时间列表进行比较偏移量。然后,只要看到变化,您就可以推断 DST 的遵守情况。希望这有帮助!
Unfortunately SQL Server provides no explicit DST flags or functions.
However, after DST takes effect this year you can compile a new list of offsets for each server,
datediff(hh,getutcdate(),getdate())
, and compare it with your current list of standard time offsets. You can then infer DST observance wherever you see a change.Hope this helps!