I'm trying to get the day of the month before a Date, this is what I have
var date = new Date();
var day = date.getDay();
var month = date.getMonth() + 1;
var year = date.getFullYear();
var yesterday = new Date(date.getTime());
yesterday.setDate(date.getDate() - 3);
var dayBefore = yesterday.getDay();
var MonthBefore = yesterday.getMonth() + 1;
On the log of yesterday I get
Sun Apr 30 2017 16:24:33 GMT-0500
Not really yesterday, because I was trying to get a day before the current month, but I get the last month, now when I want to get the day and month of that date, so I use getDate() and getMonth(), I get the month correctly with
MonthBefore = yesterday.getMonth() + 1;
this gives me 4 (april), but with the day (30) I get 0 using
dayBefore = yesterday.getDay();
Here is the jsfiddle: https://jsfiddle.net/4pf7bczv/