I need to find dinamically given today's date one year ago the same day.
So if today is Monday i need to find the equivalent to today's Monday but one year ago.
Like 03/03/2017
(Friday) would find me 04/03/2017
(Friday).
16/02/2017
(Thursday) would find me 18/02/2017
(Thursday) and so on.
What I am really interested is in finding the day more than the digits. I tried the following:
Date.prototype.addDays = function (days) {
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
}
var dateObj = new Date();
var wanted= dateObj.addDays(-365 + 1);
But of course wanted
has to change dinamically so this doesn't work.
Next I tried finding out the number in the year of that specific Friday in 2017 and then finding that same number in 2017 trying to somehow adapt
This example
But in this case it only counts the number of fridays not the number and I couldn't get it to work.
Maybe the best way would be to be guided by the number of the week and not just the closest Friday to the same number of the date.
Is there any way to do this using only JavaScript (without libraries like Moment.js)