简体   繁体   English

如何在特定时区指定“今天的开始”?

[英]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.

相关问题 PostgreSQL:如何基于相同的开始和结束时间(没有时区的时间戳)联接两个表? - PostgreSQL: How do I join two tables based on same start and end time (timestamp without time zone)? 在Postgres中,如何从给定的TIMESTAMP WITH TIME ZONE列中提取月份(根据特定的时区)? - In Postgres, how do you extract the month (according to specific timezone) from a given TIMESTAMP WITH TIME ZONE column? 如何将PostgreSQL数据库中的时间戳转换为用户时区时间? - How do I convert the time stamps from a PostgreSQL DB into user-time-zone times? Rails / Postgresql:如何在特定时区按日期使用日期时间字段快速分组记录? - Rails / Postgresql: How can I quickly group records using a datetime field by date in a specific time zone? 如何在 plpgsql 中编写 function 将日期与没有时区的时间戳进行比较? - How do I write a function in plpgsql that compares a date with a timestamp without time zone? 持久化到 PostgreSQL`timestamp with time zone` 时,如何防止 Hibernate 将 ZonedDateTime 转换为 UTC - How do I prevent Hibernate from converting ZonedDateTime to UTC when persisting to PostgreSQL `timestamp with time zone` 在 PostgreSql 中创建表时如何为时间戳列指定时区 - How to specify time zone for the time stamp column when creating table in PostgreSql 营业时间是否需要TIMESTAMP WITH TIME ZONE? - Do I need TIMESTAMP WITH TIME ZONE for opening hours? 如何在DAO实现类中将纪元格式日期转换为PostgreSQL数据库日期(无时区的时间戳),反之亦然 - How do I convert epoch format date to PostgreSQL database date (timestamp without time zone) in DAO implementation class or vice versa 如何将没有时区的时间转换为没有时区的时间戳? - How to convert time without time zone to timestamp without time zone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM