gpt4 book ai didi

SQL GetDate() 返回错误的时间

转载 作者:行者123 更新时间:2023-12-03 03:38:49 24 4
gpt4 key购买 nike

我在使用 GetDate() 时遇到问题,由于某种原因未返回正确的时间(比实际时间提前 7 小时),我正在使用 AZURE code> 并且数据库配置了正确的位置(美国西部)。我将不胜感激任何帮助!

我尝试运行这个脚本:

SELECT id,
status,
AcceptedDate,
Getdate(),
Datediff(hour, AcceptedDate, Getdate())
FROM orderoffers
WHERE status = 'Accepted'

最佳答案

无论数据中心如何,Azure SQL 数据库始终采用 UTC。您需要在应用程序中处理时区转换。

在这种情况下,由于您想要将“now”与数据列进行比较,请确保 AcceptedDate 也存储在 UTC 中。

Reference

关于SQL GetDate() 返回错误的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711112/

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