JavaScript: how to calculate the date that is 2 days ago? [duplicate]

If you have a date object, you can set it to two days previous by subtracting two from the date:

var d = new Date();
d.setDate(d.getDate() - 2);
console.log(d.toString());

// First of month
var c = new Date(2017,1,1); // 1 Feb -> 30 Jan
c.setDate(c.getDate() - 2);
console.log(c.toString());

// First of year
var b = new Date(2018,0,1); // 1 Jan -> 30 Dec
b.setDate(b.getDate() - 2);
console.log(b.toString());

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)