【问题标题】:postgresql: how to select w.r.t to time stamp in different formatpostgresql:如何选择 w.r.t 以不同格式的时间戳
【发布时间】:2021-01-30 16:39:33
【问题描述】:

我有一张表,其中created_at 列为timestamp with time zone

我的数据库时区是“UTC”,所有时间都存储在 UTC

我有时间"2021-01-29 11:30 AM"时区America/New_York

现在我希望它使用来获取数据

SELECT "id",
       "created_at"
FROM sampletable
WHERE created_at >= (my time at America/New_York)
ORDER BY id DESC

那么如何在 sql 中使用时区 America/New_York"2021-01-29 11:30 AM" 来获取我的数据

【问题讨论】:

    标签: postgresql


    【解决方案1】:
    SELECT id, created_at
      FROM sampletable
     WHERE created_at >= timestamp '2021-01-29 11:30 AM' at time zone 'America/New_York'
     ORDER BY id DESC;
    

    您可以查看documentation 了解详情。

    对于其他日期/时间格式,例如日-月-年,您可以使用 to_timestamp 函数。

    SELECT to_timestamp('29-01-2021 11:30 AM', 'dd-mm-yyyy hh:mi AM')::timestamp at time zone 'America/New_York';
    

    【讨论】:

    • timestamp '2021-01-29 11:30 AM' 我可以有任何其他格式,例如day-month-year,我该如何提及
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多