new Date()
getRecentDay_Date(-3);
getRecentDay_Date(-7);
getRecentMonth_Date(1);
getRecentMonth_Date(3);
getRecentMonth_Date(6);
getRecentMonth_Date(12);
function getRecentDay_Date (n) {
var dd = new Date();
dd.setDate(dd.getDate() + n);
var y = dd.getFullYear();
var m = dd.getMonth() + 1;
var d = dd.getDate();
let day = y + '-' + m + '-' + d;
console.log(day);
return day;
},
function getRecentMonth_Date(n) {
let result = '';
const datenow = new Date();
const dateend =
datenow.getFullYear().toString() +
'-' +
(datenow.getMonth() + 1).toString() +
'-' +
datenow.getDate().toString();
datenow.setMonth(datenow.getMonth() - n);
let dyear = datenow.getFullYear();
let dmonth = datenow.getMonth() + 1;
dmonth = dmonth < 10 ? 0 + dmonth : dmonth;
let dday = datenow.getDate();
const datestart =
dyear.toString() + '-' + dmonth.toString() + '-' + dday.toString();
result += datestart + ',';
result += dateend;
console.log(datestart);
return result;
},