Is it possible to have a code that is similar to this logic:
DECLARE @LAST_MONTH
SET @LAST_MONTH = BETWEEN DATEADD(mm,-1,GETDATE()) AND DATEADD(mm,-2,GETDATE())
Except, this code doesn't work.
Is it possible to have a code that is similar to this logic:
DECLARE @LAST_MONTH
SET @LAST_MONTH = BETWEEN DATEADD(mm,-1,GETDATE()) AND DATEADD(mm,-2,GETDATE())
Except, this code doesn't work.
You need two variables... a startdate
and an enddate
Using this post, here is how.
declare @startdate date = (select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)) --First day of previous month
declare @enddate date = (select DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) --Last Day of previous month
Then, use these in your where
clause:
select...
from ...
where dateCol between @startdate and @enddate