Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I want to know that how can i get data from last three months to now!! for example data from last three month to todays date (getdate())Thanks
MichaelP
Jedi Yak
2489 Posts
Posted - 2006-02-07 : 15:56:47
Search the Books Online for DateAdd and DateDiffYou're query should look something like this
SELECT field1, field2from MytableWHERE mydate BETWEEN GetDate() AND DATEADD(mm, -3, GetDate())
Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2006-02-07 : 15:57:58
WHERE SomeDateColumn >= DATEADD(m, -3, GETDATE()) AND SomeDateColumn <= GETDATE()Tara Kizeraka tduggan