Reputation: 47
I need to run SQL Server code on the 1st of the month that will generate these results:
CurrMonth CurrYear QtStrtMonth
June 2018 April
I can get the first 2 columns like this:
select DATENAME(MONTH, DATEADD(MONTH, MONTH(GETDATE()), 0) -1) as CurrMonth ,datepart(yyyy,(getdate()) ) as CurrYear
But this:
DATENAME(MONTH, DATEADD(MONTH, MONTH(GETDATE()), 0) -4) as QtStrtMonth,
does not give me the 3rd column.
Any ideas how I can easily get the NAME of a month "3 months ago"
Thanks in advance
Upvotes: 0
Views: 111
Reputation: 1270553
I would simply use:
select datename(month, dateadd(month, -4, getdate()))
If you need the date of the month that starts the quarter:
select datename(month, dateadd(quarter, datediff(quarter, 0, getdate()), 0))
Upvotes: 5