我正在用 UTC 时间存储日期时间字段。我们需要使用 CST 时区过滤记录。我试过这个查询:
select id, CreatedOn,
CreatedOn AT TIME ZONE 'UTC' AT TIME ZONE 'Central Standard Time' AS LocalTime
from Status
WHERE CAST((CreatedOn AT TIME ZONE 'Central Standard Time') AS date) = '2018-09-06'
order by CreatedOn desc;
问题是它还带来了那些在 UTC 时间更改为 9 月 6 日晚上的 CST 时间 9 月 5 日保存的记录。在 CST 时间仅过滤掉 9 月 6 日记录的正确方法是什么?
我发现查询有问题,我在 where 子句中遗漏了 'UTC' AT TIME ZONE。这是有效的正确查询:
select id, CreatedOn,
CreatedOn AT TIME ZONE 'UTC' AT TIME ZONE 'Central Standard Time' AS LocalTime from CosmoStatus WHERE CAST((CreatedOn AT TIME ZONE
'UTC' AT TIME ZONE 'Central Standard Time') AS date) = '2018-09-06'
order by CreatedOn desc;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句