Mibby Mibby - 1 month ago 13
SQL Question

SQL Server: Determining games made more than 2 years ago

The question I have is Which developers have games that were released more than two years ago?

My code looks like this:

SELECT
devName
FROM DEVELOPER as d
INNER JOIN GAME as g ON d.devID = g.devID
WHERE gameReleaseDate < (WHAT GOES HERE?);


I'm unsure how to properly have it find games released more than two years ago, I'm most likely failing to remember something very basic I dont want the answer just how to determine if something is below a certain amount of years.

Answer

I think something like this should work (assuming that the field being compared is one of the DATE / DATETIME data types):

DATEADD(YYYY, -2, GETDATE())

DATEADD Example in Docs

DATEADD on MSDN