Reputation: 77
How can I subtract 3 months from the GETDATE()
function?
What I am trying to do is get the last day of the month 3 months prior to the current month. So if today is 10.22.2012 how can I subtract 3 months from the current date and print the last day of that month, so I am looking to get this date: 07.31.2012?
Here is what I have so far but it only prints the last day of previous month:
DATEADD(MILLISECOND, -3,
DATEADD(MONTH, DATEDIFF(MONTH, -4, GETDATE()), 0))
Not printing what I need. Any help is greatly appreciated.
Upvotes: 2
Views: 696
Reputation: 107716
Last day of the month 3 months prior to the current month
DATEADD(M,DATEDIFF(M,0,GETDATE())-2,0)-1
Upvotes: 8