Sql server 如何在SQL Server中的select查询中添加日期?

Sql server 如何在SQL Server中的select查询中添加日期?,sql-server,Sql Server,为这个不清楚的问题道歉,我不知道该如何命名这个问题。我是SQL Server新手。我的表中有两列,一列名为datetimeRented,另一列名为datetimeReturned。我希望有一个select查询,用于计算过期(+48小时)的电影,以便它可以大致如下: select * from ---- [where datetimeReturned is datetimeRented + 2 DAYS] --- something which essentially does something

为这个不清楚的问题道歉,我不知道该如何命名这个问题。我是SQL Server新手。我的表中有两列,一列名为
datetimeRented
,另一列名为
datetimeReturned
。我希望有一个select查询,用于计算过期(+48小时)的电影,以便它可以大致如下:

select *
from ----
[where datetimeReturned is datetimeRented + 2 DAYS] --- something which essentially does something like this.
我只是想知道我需要做些什么来解决这个问题,谢谢:)

使用

例如:

WHERE datetimeReturned > DATEADD(day, 2, datetimeRented)

DATEADD函数对于此任务非常有用

DATEADD(dd,2,GETDATE())
将在给定日期(本例中为当前日期)上添加天数(dd),2

你的where子句可以是这样的

where datetimeReturned > DATEADD(dd, 2, datetimeRented)

我不知道这个函数的存在:)不批评这个问题。这是完全正确的。重复是因为内容已存在。如果你知道要搜索什么,问题和答案可以不费吹灰之力就找到。是我一个人,还是最近这种克隆反应在这里变得越来越普遍?时机不好,我们两人同时提交了答案。