【问题标题】:Postgresql - Select between specific Time and Date RangePostgresql - 在特定时间和日期范围之间进行选择
【发布时间】:2015-06-12 08:58:05
【问题描述】:

我正在尝试从我的表格中获取一些数据 - 我只需要固定日期范围内的特定时间(一天晚上 22:00 到第二天早上 06:00 之间)。

这是我目前所拥有的:

create new_table
as select table.v1, table.localminute from table 
where date(table.localminute) between
date('2013-11-01 00:00:00-05') and date('2014-12-01 00:00:00-05') 
and hour(table.localminute) between 22 and 6

我不确定如何获取每天 22:00:00-05 和 06:00:00-05 之间的数据。

我也考虑过在日期中使用通配符,但要么不起作用,要么我的实现不正确。任何帮助将不胜感激!

我使用下面链接中的信息来设置它 - 不知道我需要做什么。

Select between date range and specific time range

【问题讨论】:

    标签: postgresql date


    【解决方案1】:
    SELECT v1, localminute 
    FROM "table" 
    WHERE localminute BETWEEN '2013-11-01'::date AND '2014-12-01'::date 
    AND (extract('hour' from localminute) >= 22 OR extract('hour' from localminute) < 6);
    

    【讨论】:

    • 谢谢!这帮助我指出了正确的方向。无法真正提取“日期”,所以这就是最终查询对我的看法:发现您只能提取部分时间戳,如日、小时、年,因此从查询中删除了该部分:再次感谢您的帮助!
    • 谢谢!我会投票给答案,但我还没有足够的积分。
    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    相关资源
    最近更新 更多