Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • 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))
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


Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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