【问题标题】:What is the equivalence of MS SQL Server's getutcdate() in postgresql? [duplicate]MS SQL Server 的 getutcdate() 在 postgresql 中的等价物是什么? [复制]
【发布时间】:2015-05-05 17:50:15
【问题描述】:

我从 SQL Server 迁移到 PostgreSQL。如何翻译 getutcdate 函数,如:

Insert into mytable (mypk, toucheddate) values (99, getutcdate() )

(我不是要求与 MySQL 等效,这是一个不同的平台)

【问题讨论】:

  • 它给出了一个提示,但它没有回答我的问题,因为我不知道 MySQL 函数是否等同于 SQL Server 函数。我的问题不够精确,刚刚编辑完成。

标签: sql-server postgresql


【解决方案1】:

至少有两种方法可以获取 UTC 中的当前时间:

select now() at time zone 'utc';

select current_timestamp at time zone 'utc';

【讨论】:

    【解决方案2】:

    Postgres 有current_timestamp 代表当前日期和时间,current_date 代表当前日期和current_time 代表当前时间。

    更多详情请见the documentation

    【讨论】:

    • 这不是UTC,而是当地时间。需要current_timestamp at time zone 'utc'
    【解决方案3】:

    相信你在找now():

    postgres=# select now();
                now
    ---------------------------
     2015-05-05 13:52:45.81-04
    (1 row)
    

    【讨论】:

    • 这还不够,因为他们想要 UTC 时间。这给出了当地时间。需要now() at time zone 'utc'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 2010-10-16
    • 2010-12-01
    相关资源
    最近更新 更多