In this comprehensive article, I will walk you through multiple proven methods for retrieving the previous month’s data in SQL Server, complete with practical examples.
How To Get Previous Month Data From Current Date In SQL Server
Now, let’s explore the various techniques to retrieve the previous month’s data in SQL Server.
Method 1: Using DATEADD and EOMONTH Functions
The most straightforward approach is to combine the DATEADD and EOMONTH functions.
SELECT
DATEADD(DAY, 1, EOMONTH(GETDATE(), -2)) AS FirstDayOfPreviousMonth,
EOMONTH(GETDATE(), -1) AS LastDayOfPreviousMonth
This query works by calculating the end of the month before last (using EOMONTH with -2), then adding one day to get the first day of the previous month. For the last day, we simply use EOMONTH with -1.
Let’s break down how this works:
- GETDATE() returns the current date (e.g., April 28, 2025)
- EOMONTH(GETDATE(), -1) returns March 31, 2025 (last day of previous month)
- EOMONTH(GETDATE(), -2) returns February 28, 2025 (last day of month before last)
- DATEADD(DAY, 1, EOMONTH(GETDATE(), -2)) returns March 1, 2025 (first day of previous month)
After executing the above query, I got the expected output as shown in the screenshot below.

Example
Here’s how you might use this to query actual data. The below query will return all sales from the previous month.
SELECT
sale_date,
sale_amount,
TotalSales
FROM
Sales
WHERE
sale_date BETWEEN
DATEADD(DAY, 1, EOMONTH(GETDATE(), -2)) AND
EOMONTH(GETDATE(), -1)
ORDER BY
sale_dateAfter executing the above query, I got the expected output as shown in the screenshot below.

Method 2: Using DATEADD with DATEDIFF
If you’re working with an older version of SQL Server that doesn’t support EOMONTH, or if you prefer a different approach, the DATEADD and DATEDIFF combination offers a robust alternative.
SELECT
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AS FirstDayOfPreviousMonth,
DATEADD(DAY, -1, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) AS LastDayOfPreviousMonth
This method works by:
- Using DATEDIFF to calculate the number of months between January 1, 1900 (represented by 0) and the current date
- Subtracting 1 to get the previous month
- Using DATEADD to find the first day of the previous month
- Finding the last day by calculating the first day of the current month and subtracting one day
After executing the above query, I got the expected output.

Example
This query retrieves the total sales by sale date for the previous month, sorted by performance.
SELECT
sale_date,
SUM(sale_amount) AS MonthlySales
FROM
Sales
WHERE
sale_date BETWEEN
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AND
DATEADD(DAY, -1, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))
GROUP BY
sale_date
ORDER BY
MonthlySales DESC
After executing the above query, I got the expected output as shown in the screenshot below.

Method 3: Using Month and Year Comparisons
Sometimes, you may want to filter by month and year rather than exact dates. You can use the below query for that purpose. This approach extracts the month from a date that’s one month before today, then filters records where both month and year match.
SELECT
sale_amount
FROM
Sales
WHERE
MONTH(sale_date) = MONTH(DATEADD(MONTH, -1, GETDATE())) AND
YEAR(sale_date) = YEAR(DATEADD(MONTH, -1, GETDATE()))After executing the above query, I got the expected output.

Method 4: Using DATEADD with EOMONTH Functions in a different way like Oracle
We can use the following query.
SELECT
DATEADD(DAY, 1, EOMONTH(GETDATE(), -2)) AS FirstDayPrevMonth,
EOMONTH(GETDATE(), -1) AS LastDayPrevMonth
After executing the above query, I got the expected output as shown in the screenshot below.

Conclusion
Retrieving the previous month’s data is essential for business analysis, reporting, and data monitoring. Knowing how to query previous month’s data in SQL Server effectively is straightforward using the approaches mentioned in this article.
You may also like the following articles.
- SQL Server Greater Than Date
- SQL Server Get Yesterday’s Date
- SQL Server Get UTC Date
- Trunc Date In SQL Server
- SQL Server GROUP BY Date
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.