Find previous month data

Posted on 2009-04-28
Last Modified: 2012-05-06
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))
Question by:Fairfield
    1 Comment
    LVL 142

    Accepted Solution

    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

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
    In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now