SQL deduct one month from a date but keep the order correct

1932 views sql
2

The title is probably worded poorly but what I want to have is say I do this

SELECT DATEADD(month,-1,'4/30/2019')

Instead of getting 3/30/2019 I want 3/31/2019, how do we do this?

answered question
John Cappelletti

If 2012+ EOMonth(DATEADD(month,-1,'4/30/2019'))

forpas

Do you want the last day of the previous month?

Snorrlaxxx

@forpas Yes, I do

Add a Comment

1 Answer

13
forpas 0 Comments

If you want the last day of the previous month:

DATEADD(MONTH, DATEDIFF(MONTH, 0, '2019-04-30'), -1)

posted this

Please login first before posting an answer.