How to get previous month in SQL

I have the code shown below that is part of my where clause.  I need to get all data for the previous calendar month, so July 1 - 31 right now since we're in August.  This statement is giving me all July data, but includes multiple years in it.  How can I fix that?

where datepart(m, BEG_DATE) = datepart(m, dateadd(m, -1, getDate()))
and datepart(y, BEG_DATE) = datepart(y, dateadd(m, -1, getDate()))

Open in new window

fcsITAsked:
Who is Participating?
 
Vijaya Reddy Pinnapa ReddyCommented:
where beg_date >= dateadd(m, datediff(m, 0, GETDATE()) - 1, 0)
   AND beg_date < dateadd(m, datediff(m, 0, GETDATE()), 0)
0
 
fcsITAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.