First and Last day of Previous Month
Views (1394)
In the accounting world I so often need to limit my selection criteria to the first and last day of the previous month. This is certainly not a secret formula, but I now have a place where I can look it up. Sadly, I have not memorized this formula
First Day of Previous Month:
DATEADD (m,-1, DATEADD(d,1-DATEPART(d,GETDATE()),GETDATE()))
Last Day of Previous Month:
DATEADD(d,-DATEPART(d,GETDATE()),GETDATE())Example:
SELECT * FROM SOP30200
WHERE
VOIDSTTS = 0 and DOCDATE between
DATEADD (m,-1, DATEADD(d,1-DATEPART(d,GETDATE()),GETDATE())) and
DATEADD(d,-DATEPART(d,GETDATE()),GETDATE())
Until next post!
This was originally posted here.

Like
Report
*This post is locked for comments