在PostgreSQL中检查日期是否超过3岁 [英] Checking if date is more than 3 years old in PostgreSQL
本文介绍了在PostgreSQL中检查日期是否超过3岁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我有一个包含4个日期的表:
At the moment I have a table that contains 4 dates:
CREATE TABLE dates (
date date
);
11-mar-2008
25-now-2007
18-apr-2012
20-apr-2012
我想有一个声明,我可以找到所有年龄大于三岁的日期。这应该是前两个日期。
I would like to have a statement where I can find all dates that are older than three years old. That should be the first 2 dates.
到目前为止,我有:
SELECT * FROM dates WHERE date = now()::-1095;
但这不行。
任何帮助将不胜感激。
推荐答案
尝试这样:
SELECT * FROM dates WHERE date < now() - '3 years'::interval;
另外,命名您的列日期
不是一个很好的做法,因为这是PostgreSQL中的一个保留字。
Also, naming your column date
is not a good practice, as this is a reserved word in PostgreSQL.
这篇关于在PostgreSQL中检查日期是否超过3岁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文