Hey i want to get the last 14 days in JavaScript. I tried following code:
var ourDate = new Date();
for (let index = 0; index < 14; index++) {
var pastDate = ourDate.getDate() - index;
ourDate.setDate(pastDate);
console.log(ourDate.toDateString(), " - ", index);
}
but the console output is following:
Sat Jan 23 2021 - 0
Fri Jan 22 2021 - 1
Wed Jan 20 2021 - 2
Sun Jan 17 2021 - 3
Wed Jan 13 2021 - 4
Fri Jan 08 2021 - 5
Sat Jan 02 2021 - 6
Sat Dec 26 2020 - 7
Fri Dec 18 2020 - 8
Wed Dec 09 2020 - 9
Sun Nov 29 2020 - 10
Wed Nov 18 2020 - 11
Fri Nov 06 2020 - 12
Sat Oct 24 2020 - 13
Which does not make sense. Could someone help me with this? I used this code: LINK TO TUTORIAL