• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Find previous month data

I have a date field that I am trying to find the previous months data.  I am trying us the following filter, however it is not pulling the correct data.  Is this correct?

< DATEADD(d, - 1, DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0))
0
Fairfield
Asked:
Fairfield
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I would try this:
yourfield < CONVERT(datetime, CONVERT(varchar(8), getdate(), 120) + '01', 120)
AND yourfield >= DATEADD(MONTH, -1, CONVERT(datetime, CONVERT(varchar(8), getdate(), 120) + '01', 120))

Open in new window

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.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now