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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Current date minus one month

Author  Topic 

thoron6
Starting Member

7 Posts

Posted - 2014-08-05 : 11:03:11
Hey all,

I am looking to run a report that brings back data that was updated in the past month:

SELECT *
FROM Table
Where Date (between todays date and one month ago)

Any help would be appreciated.

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-08-05 : 11:20:51
WHERE Date BETWEEN DATEADD(MONTH, -1, GETDATE()) AND GETDATE()



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-08-05 : 12:46:19
I prefer to include full days only from history, so that a report run at 11:15 returns the same results as one run at 11:25.


Where Date BETWEEN DATEADD(MONTH, -1, Dateadd(DAY, Datediff(DAY, 0, Getdate()), 0)) AND Getdate()
Go to Top of Page

thoron6
Starting Member

7 Posts

Posted - 2014-08-06 : 03:21:39
Brilliant,

Thank you both. I'll look up the Dateadd function now so that I can use it in the future!

Thanks again!
Go to Top of Page
   

- Advertisement -