Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] Subtract month from date in format yyyyMMdd

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
//Input String yyyymmdd
var date_string = '20200101'
 
//Create date object
var oDate = new Date(date_string.substr(0, 4), date_string.substr(4, 2), date_string.substr(6, 2))
 
oDate.setMonth(oDate.getMonth() - 1)
 
var year = oDate.getFullYear().toString()
var month = oDate.getMonth().toString()
var day = oDate.getDay().toString()
 
//Add leading zero's
if (month.length === 1 ) {
    month = '0' + month
}
if (day.length === 1 ) {
    day = '0' + day
}
 
//Return string: 20191201
var sDate =  year + month + day

[ABAP] Get month name

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
METHOD get_month_name.
 
   DATA: month_names TYPE TABLE OF t247.
 
   CALL FUNCTION 'MONTH_NAMES_GET'
     TABLES
       month_names = month_names
     EXCEPTIONS
       OTHERS      = 0.
 
   TRY.
       r_name = month_names[ mnr = i_month ]-ltx.
 
     CATCH cx_sy_itab_line_not_found.
   ENDTRY.
 
ENDMETHOD.