1
votes

I'm trying to get the year of the previous month.

For example in July 2017 I want result 2017. But in January 2017 I want result 2016 and in Feb 2017 I want result 2017. Using SQL Server.

2

2 Answers

2
votes

sql server?

select datepart(year, dateadd(month, -1, getdate()))
1
votes
select year(dateadd(month,-1,GETDATE()));