I have a business in my Date. I need change date below
for each date before 25 of each month I want get 25 of month before and for each date after 25 of each month I want get 25 of the same month.
for 2015/06/24 (or 2015/06/06) I need 2015/05/25
and for 2015/06/25 (or 2015/06/30) I need 2015/06/25
I write this query :
DECLARE @A DATE = '2015/06/01' SELECT ( CASE WHEN DATEDIFF(MONTH, DATEADD(Day, -25, @A), @A) = 0 THEN DATEADD(DAY, 25, DATEADD(Day, -DAY(@A), @A)) ELSE DATEADD(DAY, 25, DATEADD(MONTH, -1, DATEADD(Day, -DAY(@A), @A))) END )
But I am looking for better solution.