如何提取日期并进行+/- 30天的检查参数

时间:2018-08-29 09:36:33

标签: sql postgresql postgresql-9.3

我需要找到如何提取日期

然后在之间使用语句

:日期是用户的输入

select userID,:date,reportid
from usertable
where userID = '120429'
and 
:date between (:date-30 days) and (:date +30 days)

1 个答案:

答案 0 :(得分:2)

您可以使用date/time arithmetic operators

:date + interval '30 days'

:date - interval '30 days'