Known YearMonth exergue is integer fields through the years to reduce fixed number of days, want to the result of the following
Results YearMonth day
202011-50, 202009
202011-30 202010
The 202011-10 202010
The current value of 202011 (the default for the current month's no. 1), 50 days return for 202009, January 1, 2020-50 days=in September 2020,
select SUBSTRING (cast (replace (convert (varchar (9), dateadd (month, 0, getdate ()), 120), '-', ') as varchar), 0, 7)
CodePudding user response:
DECLARE @ DT VARCHAR (10)DECLARE @ DIFF INT
The SET @ DT='202011'
The SET @ DIFF=50
-
SELECT the CONVERT (VARCHAR (6), DATEADD (DAY @ the DIFF, CAST (@ DT + '01' AS the DATE)), 112).