How can I get a date 60 months ago?

Asked

Viewed 1,633 times

2

I want to get some date 60 months ago.

I’m in a project that shows only the files sent 60 months, but it’s 60 months and not 5 years, maybe it doesn’t make any difference.

Any idea? I tried using Datediff, but I’m unsuccessful. I want to do this in SQL Procedure

SELECT CAST(DATEPART(YY, GETDATE()) - 5  AS VARCHAR)

Note that the "5" before the varchar, refers to the 60 months or 5 years, however, it wants 60 months. How could I catch this date from 60 months ago.

  • Post the code you tried with datediff.

1 answer

10


In your query, you should use DATEADD

SELECT GETDATE() AS Hoje, DATEADD(M, -60, GETDATE()) AS [60MesesAtras]

Since you did not provide more details on your question, this is as much as I can help you.

Example in Sqlfiddle

  • Thanks gmsantos, I did not remember the dateadd... What a slow guy! Thank you really ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.