user2447136
user2447136

Reputation: 189

Get previous months date in year and month format

What function can I use to get the previous months date in the format yyyy-mm . This is what I have tried.

SELECT FORMAT (getdate(), 'yyyy-MM') as date

Upvotes: 0

Views: 104

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175556

You could use DATEADD:

SELECT FORMAT (DATEADD(mm, -1, getdate()), 'yyyy-MM') as date

db<>fiddle demo

Upvotes: 5

Related Questions