我正在使用postgres,我有两个表:
TIME_FRAMES
ID | TIME_ZONE | DAY_OF_WEEK | START | END | LECTURE_ID
LECTURES
ID | CLASS | TEACHER
我想运行一个查询来获取现在发生的所有讲座(运行查询的 utc 时间)。
我看到有一个时区列表 Postgres 支持,所以这些值是我坚持的值。
谢谢
使用日期算术:
SELECT *
FROM time_frames
WHERE current_timestamp BETWEEN
(CAST (current_date || ' ' || start
AS timestamp without time zone
) AT TIME ZONE time_zone)
AND
(CAST (current_date || ' ' || "end"
AS timestamp without time zone
) AT TIME ZONE time_zone)
AND extract(dow FROM current_date) = day_of_week;