'How to find the next 31st March

At the point of running some code I want to be able to return the next 31st of March.

So if run today tye date returned would be 31st March 2023. But if the same code was run back on say the 1st of March 2022 then the 31st of March would be returned....not sure of the best way to achieve this.



Solution 1:[1]

A little date arithmetic should work here:

DATEFROMPARTS(YEAR(DATEADD(MONTH,-3,GETDATE())+1),3,31)

Solution 2:[2]

Hi thanks for getting me on the right track. I went with this very similar code -

DATEFROMPARTS (YEAR(DATEADD(MONTH,-3,GETDATE())+1), 3, 31 )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ikilledbill