简体   繁体   English

如何在PostgreSQL中减去没有时区的时间戳

[英]How to substract timestamp without timezone in PostgreSQL

I'm currently using PostgreSQL 8.4 and need to substract from now() date on day. 我当前正在使用PostgreSQL 8.4,需要从当天的now()日期中减去。 What I tried is now() - 1 and it didn't work. now() - 1尝试的是now() - 1 ,但没有用。 Although that page said that we could use operator - to perform operations on date. 尽管该页面说我们可以使用运算符-在日期上执行操作。 More preciseli I recieved 我收到的更准确

ERROR:  operator does not exist: timestamp with time zone - integer

Any ideas? 有任何想法吗?

PostgreSQL can't use mathematical functions directly I think. 我认为PostgreSQL无法直接使用数学函数。 But we can use date function such interval function in PostgreSQL will solve your problem. 但是我们可以使用date函数,例如PostgreSQL中的interval函数将解决您的问题。

Try below subtract eg: 请尝试以下减去例如:

select interval '2 day' - interval '1 day';
select now() - interval '1' ;

You can also refer to PostgreSQL 8.4 documentation. 您也可以参考PostgreSQL 8.4文档。

http://www.postgresql.org/docs/8.4/static/functions-datetime.html http://www.postgresql.org/docs/8.4/static/functions-datetime.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM