如何使用 Postgresql 获取当前日期 - 两周日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23557804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:26:33  来源:igfitidea点击:

How to get current date - two weeks date using Postgresql?

sqlpostgresqldate

提问by AKIWEB

I am working with Postgresqldatabase. I need to get date which is two weeks prior to current date using Postgresqldatabase.

我正在使用Postgresql数据库。我需要使用Postgresql数据库获取当前日期前两周的日期。

select date(now() - interval '2 week') from test_base

If today's date is 2014-05-08then above sql should give me 2014-04-24?

如果今天的日期是2014-05-08上面的 sql 应该给我2014-04-24吗?

But somehow above query is not working at all?

但不知何故,上面的查询根本不起作用?

回答by Patrick

SELECT now() - interval '2 week';

This works just fine. What is the exact error you are getting?

这工作得很好。你得到的确切错误是什么?

Since you are not pulling any data from table test_basethere is no need to include that in a FROMclause.

由于您没有从表中提取任何数据,test_base因此无需将其包含在FROM子句中。