SQL Query to Get Last 3 Months Records in SQL Server

← PrevNext →

In SQL Server, you can use the DATEADD() function to get last 3 months (or n months) records. In previous tutorial, I have shown how to use this function to get previous month records. Now, here I'll show you how to get last 3 months data in SQL Server.


The DATEADD() function returns a date time (smalldatetime).

DATEDADD(interval, increment (int), expression (date))

This function is commonly used in date related queries.

Let us create a table first in SQL Server. I have an employee table with few records in it. The employee table has a date column (the last column). See the image.

Get last 3 months Records in SQL Server

👉 Related example... how to get the last 3 records or rows in a table in SQL Server (3 different methods)
Get the last 3 rows in a table

Query to get Last 3 Months Records

WHERE JoiningDate >= DATEADD(M, -3, GETDATE())

The Output

Assuming that the current month is May. The result shows records for the month of Feb.

Showing Last 3 Months Records in SQL Server

Its a one line query. The function DATEADD() takes 3 parameters.

1) The first parameter is the M, which denotes a month. You can replace the M with the MONTH. Like this,


2) The second parameter is "increment" (an integer value or a number). I am using -3 to get the last 3 months records or data. You can use -5, -4 or any number, depending upon your requirement.

👉 How easily can you find the First and Last day (in words) of a given month using a single SQL query? See the example here.
Get the first and last day of a given month in SQL Server

Thought you should know: You can use a variable to specify a number, and use the variable inside the "DATEADD()" function. Like this,

SET @D = 3

3) The third parameter inside the DATEADD() function, is an expression or date. I am using the "GETDATE()" function for current month.

Note: The DATEADD() function is also supported by Azure SQL Database.

That’s it. Thanks for reading. 🙂

← PreviousNext →