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

[SAPUI5] Create date object in UTC YYYY-MM-ddTHH:mm:ss

https://sapui5.hana.ondemand.com/#/api/sap.ui.core.format.DateFormat%23methods/format

            const today = new Date()
            const oDateTimeFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
                pattern: "yyyy-MM-ddTHH:mm:ss",
                UTC: true
            })
            const todayISO = oDateTimeFormat.format(today)

The UTC flag can also be set, when calling the format function.

            const today = new Date()
            const oDateTimeFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
                pattern: "yyyy-MM-ddTHH:mm:ss",
                //UTC: true
            })
            const todayISO = oDateTimeFormat.format(today, true)

[JavaScript] Subtract month from date in format yyyyMMdd

//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