I want to subtract 3 months as so:
DECLARE @ReportingDate date = '6/30/2019'
SELECT DATEADD(MONTH, -3,@reportingDate)
But what I get returned is '2019-03-30' when the correct end of month should be '2019-03-31'. How do I fix this?
I want to subtract 3 months as so:
DECLARE @ReportingDate date = '6/30/2019'
SELECT DATEADD(MONTH, -3,@reportingDate)
But what I get returned is '2019-03-30' when the correct end of month should be '2019-03-31'. How do I fix this?
One easy way is:
DECLARE @ReportingDate date = '6/30/2019'
SELECT CASE
WHEN @ReportingDate = EOMONTH(@ReportingDate) THEN EOMONTH(DATEADD(MONTH, -3,@reportingDate))
ELSE DATEADD(MONTH, -3,@reportingDate)
END