April 25, 2018 at 12:42 pm
subtract 1 month from the year and month.
I have @yearmonth='2018-03' .i have data -'2018-03' and i want to have '2018-02' .it should work for last 4-5 months. I should be able to get to 2017-10 etc.
please help. Thanks.
April 25, 2018 at 12:49 pm
Papil - Wednesday, April 25, 2018 12:42 PMsubtract 1 month from the year and month.I have @yearmonth='2018-03' .i have data -'2018-03' and i want to have '2018-02' .it should work for last 4-5 months. I should be able to get to 2017-10 etc.
please help. Thanks.
This help?
DECLARE @yearmonth VARCHAR(7) ='2018-03' ;
SELECT CONVERT(VARCHAR(7),DATEADD(MONTH, -1, @yearmonth + '-01'),121);
April 25, 2018 at 12:50 pm
Lynn Pettis - Wednesday, April 25, 2018 12:49 PMPapil - Wednesday, April 25, 2018 12:42 PMsubtract 1 month from the year and month.I have @yearmonth='2018-03' .i have data -'2018-03' and i want to have '2018-02' .it should work for last 4-5 months. I should be able to get to 2017-10 etc.
please help. Thanks.This help?
DECLARE @yearmonth VARCHAR(7) ='2018-03' ;
SELECT CONVERT(VARCHAR(7),DATEADD(MONTH, -1, @yearmonth + '-01'),121);
Yes thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply