1

Apologies for the unclear question I was unsure of how to title this. I am new to SQL Server. I have two columns in my table, one called datetimeRented and one called datetimeReturned. I want to have a select query which calculates movies that are overdue (+48hrs) so that it will be something along the lines of:

select *
from ----
[where datetimeReturned is datetimeRented + 2 DAYS] --- something which essentially does something like this.

I just want to know what I would need to do to work this out, thank you :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Edwards
  • 105
  • 2
  • 7
  • possible duplicate of [SQL Server 2005 Using DateAdd to add a day to a date](http://stackoverflow.com/questions/167491/sql-server-2005-using-dateadd-to-add-a-day-to-a-date) – xQbert May 11 '15 at 19:41
  • I didn't know that this function existed :) – Edwards May 11 '15 at 19:47
  • Not critiquing the question. it's perfectly valid. The duplicate is because the content already exists. Had you known what to search for, the question and answer could have been found without added effort. – xQbert May 11 '15 at 19:49

2 Answers2

3

Use DATEADD (Transact-SQL)

For example:

WHERE datetimeReturned > DATEADD(day, 2, datetimeRented)
Pittsburgh DBA
  • 6,672
  • 2
  • 39
  • 68
0

DATEADD function is useful for this tasks.

DATEADD (dd, 2, GETDATE()) will add days (dd), 2, to the given date (in this case the current date)

So your where clause could be like this

where datetimeReturned > DATEADD(dd, 2, datetimeRented)
Zukki
  • 141
  • 5