• Luis Cazares (12/5/2013)


    DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 1, 0)

    Is getting the first day of previous month.

    DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)

    Is getting the first day of current month.

    - '00:00:01'

    Is substracting one second to get only values from previous month because BETWEEN limits are inclusive.

    There are ways to rewrite the code, but this might be the best in terms of performance and flexibility. It's basically adding months to a base date (zero or 1900-01-01) to eliminate days and time. You could use the same functionality for other datetime parts.

    DOH! I typed current month. :blush: Luis is right - it's previous month. Thanks for catching it, Luis.