【问题标题】:Get specific time period from a list of epoch in Postgres从 Postgres 中的纪元列表中获取特定时间段
【发布时间】:2018-10-27 05:39:29
【问题描述】:

我在 Postgres 中有以下带有纪元时间戳的表格。我想选择时间为 太平洋标准时间 20:00 到 21:00 的时间戳。我已经部分尝试了以下方法,但似乎无法同时提取小时和分钟。

SELECT timestamp from table where extract(‘hour’ from to_timestamp(created_at) at time zone ‘America/Los_angeles’) > 20

| created_at |

| 1526528788 |

| 1526442388 |

| 1526309188 |

| 1526359588 |

| 1526532388 |

| 1526489188 |

预期结果:

| created_at |

| 1526528788 |

| 1526442388 |

任何帮助将不胜感激。

【问题讨论】:

    标签: postgresql epoch


    【解决方案1】:

    你的意思是PST,为什么要写America/Los Angeles?它们(有时)是不同的。

    这能解决你的问题吗:

    ... WHERE extract(hour FROM
                      to_timestamp(1526309188) AT TIME ZONE 'PST'
                     ) BETWEEN 20 AND 21;
    

    【讨论】:

    • 嗨 Laurenz,通过上述解决方案,我在 21:00 之后获得了时间戳。我只想从 20:00 到 21:00 获取所有时间戳。非常感谢您的帮助。
    • 我不这么认为。可以举个例子吗?
    猜你喜欢
    • 1970-01-01
    • 2011-03-24
    • 2016-07-25
    • 1970-01-01
    • 2018-01-17
    • 2014-09-25
    • 2016-06-15
    • 2019-12-05
    • 2018-05-18
    相关资源
    最近更新 更多