user88866050 user88866050 - 5 months ago 33
SQL Question

sql query for getting data for last 3 months

How can you get today's date and convert it to

01/mm /yyyy
format and get data from the table with delivery month 3 months ago? Table already contains delivery month as
01/mm/yyyy
.

Answer
SELECT * 
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(MONTH, -3, GETDATE()) 

Mureinik suggested methond will return the same resutls. but doing this way your query can benefit from any indexes on Date_Column.

or you can check against last 90 days.

SELECT * 
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(DAY, -90, GETDATE()) 
Comments