Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you test if something is older than 3 months?

I have been having some trouble to select the rows of my table which has a date of 3 months prior of today. I tried using DATE(NOW() - INTERVAL 3 MONTH) in my where clause, but no luck. How do I check in SQL Server if a item is older than 3 months?

  UPDATE[TCTdb].[dbo].[Stock]
     SET[Warehouse] = 'old'
   WHERE [ManufacturedDate] <= DATE(NOW() - INTERVAL 3 MONTH)
like image 707
Eon Avatar asked Aug 03 '11 18:08

Eon


People also ask

How do I get last 3 months data in SQL?

In SQL Server, you can use the DATEADD() function to get last 3 months (or n months) records.


1 Answers

Your syntax appears to be wrong.

That should be

UPDATE[TCTdb].[dbo].[Stock]
    SET[Warehouse] = 'old'
WHERE [ManufacturedDate] <= DATEADD(mm, -3, GETDATE())
like image 153
Code Magician Avatar answered Sep 17 '22 15:09

Code Magician