[英]How do I specify “the start of today” in a specific time zone?
I have a table with a “timestamp with time zone” column. 我有一个带有“带时区的时间戳”列的表。 I would like to find all of the rows whose timestamp is earlier than today, where “today” is determined in a specific time zone. 我想找到时间戳早于今天的所有行,其中“今天”是在特定时区确定的。
I know how to use at time zone
to interpret a literal timestamp as being in some particular time zone, and I know how to use date_trunc
to get the beginning of this day. 我知道如何at time zone
使用将文字时间戳解释为在某个特定时区,并且我知道如何使用date_trunc
来获取当天的开头。 But I'm not sure how to combine them to get what I need. 但我不确定如何将它们结合起来以获得我需要的东西。 I tried 我试过了
select date_trunc('day', current_date at time zone 'cst');
which gave me “2015-03-16 00:00:00”, but it's unclear to me what time zone is used for this result (or whether it has one at all). 这给了我“2015-03-16 00:00:00”,但是我不清楚这个结果使用了什么时区(或者是否有一个时区)。 How can I select the beginning of the current day according to a specific time zone? 如何根据特定时区选择当天的开头?
It helped me to reframe the question as follows: what are the current date and time in the Central time zone? 它帮助我重新构建了如下问题:中心时区的当前日期和时间是多少? Then, what I want is the midnight at the beginning of that day [in the Central time zone]. 然后,我想要的是那天开始的午夜[在中央时区]。 I found that I could write this as 我发现我可以写这个
current_date::timestamp AT TIME ZONE 'cst'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.