gpt4 book ai didi

SQL - 在时区

转载 作者:行者123 更新时间:2023-12-04 23:35:04 34 4
gpt4 key购买 nike

我有这个查询正确地将中欧时间返回为 +2 小时。但是,它不会将这两个小时添加到时间中。如何添加这两个小时的时间(或 x 小时,具体取决于时区)?

DECLARE @targettimezone AS sysname = 'Central European Standard Time'
SELECT convert(datetime2,'2018-10-25T13:43:19.296Z') AT TIME ZONE @targettimezone;

最佳答案

您可以尝试使用datetimeoffset而不是 datetime2.

Defines a date that is combined with a time of a day that has time zone awareness and is based on a 24-hour clock.

然后将datetimeoffset转换成DateTime就可以得到你期望的结果了。

DECLARE @targettimezone AS sysname = 'Central European Standard Time'
SELECT cast(cast('2018-10-25T13:43:19.296Z' as datetimeoffset) AT TIME ZONE @targettimezone as datetime2);

sqlfiddle

关于SQL - 在时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52993652/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com