Verify if dates fall within 24 months [closed]

I have two date columns… What I am trying to accomplish is verifying if the two columns contain dates within the last 24 months.

So for example, today is 01/04/2024. The results should return dates that are less than or equal to this time frame.

I have attempted using the dateadd syntax to a query i am testing but not securing the correct results.

SELECT STARTDATE, ENDDATE ,DATEADD(MONTH,-4,GETDATE())

  • 1

    Columns? So this is a database question? Perhaps SQL? If so, say so. Your Questions lacks details and context. Add tags and mentions, including what database engine.

    – 




  • The IDE (like) application you are using is irrelevant, tell us what the database engine is.

    – 

  • 1

    You’re asking for results that are filtered. Have you considered using a WHERE clause in your SQL statement?

    – 

  • Please read How to Ask and how to provide a minimal reproducible example. Also please properly tag your questions (I removed all the other tags as they were irrelevant, and added the generic sql tag for now). At a minimum, provide sample data/schema, expected output, your query and actual output, errors, etc.

    – 




  • 2

    Does 24 months mean calendar months or exactly two years? What happens if today is a leap day? Why did you only subtract 4 months in the sample query?

    – 

Leave a Comment