MS SQL Server的getutcdate()在PostgreSQL中的等效函数是什么?

12

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

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

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


这个有帮助吗?https://dev59.com/3Gw05IYBdhLWcg3wmC6_ - Chris Albert
它提供了一个提示,但并没有回答我的问题,因为我不知道MySQL函数是否等同于SQL Server函数。我的问题不够精确,刚刚进行了编辑。 - ilsankergeeky
3个回答

21

获取当前UTC时间至少有两种方式:

select now() at time zone 'utc';

select current_timestamp at time zone 'utc';

0

我相信你正在寻找now()函数:

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

1
这不够,因为他们想要的是UTC时间。 这提供了本地时间。 需要是now() at time zone 'utc' - Sami Kuhmonen

0

Postgres提供current_timestamp来获取当前日期和时间,current_date用于获取当前日期,current_time用于获取当前时间。

更多详细信息请参阅文档


1
这不是UTC时间,而是本地时间。需要使用current_timestamp at time zone 'utc' - Sami Kuhmonen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接