0

I have a table with applicationdate as one of its columns. I need to filter up to the past 3 months and not just three months ago from today, that is, if today is 9/26/2022, I would like to filter from 6/1/2022, and not 6/26/2022.

This code pulls the three months ago from today

SELECT * 
FROM table 
WHERE applicationdate >= DATEADD(month, -3, applicationdate)

resulting to 6/26/2022. I am interested up to 6/1/2022

According to some googling, I can use trunc(), datetrunc() or date_trunc() to get the first day of the three months ago, but each of them throws a function error saying:

'function' is not a recognized built-in function name.

How can I filter to the first of three months ago?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
budding pro
  • 135
  • 1
  • 2
  • 10
  • Use a [calendar table](https://www.mssqltips.com/sqlservertip/4054/creating-a-date-dimension-or-calendar-table-in-sql-server/) with a column IsFirstOfMonth. then you can join to the calendar table and filter based on the columns. or have a look at: https://stackoverflow.com/questions/1520789/how-can-i-select-the-first-day-of-a-month-in-sql – Preben Huybrechts Sep 27 '22 at 04:57
  • Those functions are Oracle functions not T-SQL functions. When googling about SQL Server always use `T-SQL` in your search terms. – Nick.Mc Sep 27 '22 at 10:02

0 Answers0