Dak
Dak

Reputation: 39

To get the Year of the previous month in SQL

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.

Upvotes: 1

Views: 3542

Answers (2)

Rishabh
Rishabh

Reputation: 57

select year(dateadd(month,-1,GETDATE()));

Upvotes: 2

Dan Bracuk
Dan Bracuk

Reputation: 20794

sql server?

select datepart(year, dateadd(month, -1, getdate()))

Upvotes: 2

Related Questions