-1

I want to plot a graph by fetching the previous seven days using the present day in Javascript.

Which should pass through the tests of Leap year, days of mont(30/31), Year change.

Thank you in advance.

Preetham Sridhar
  • 155
  • 1
  • 2
  • 12
  • 1
    subtract one from the day - don't worry if it becomes zero, Date objects are very very smart - see [Date documentation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date) – Jaromanda X Sep 28 '16 at 03:33
  • 1
    Honestly, I googled literally your whole title and that was the first result. Utilize google please! – Sterling Archer Sep 28 '16 at 03:36

1 Answers1

2
var d = new Date();
var yesterday = d.setDate(d.getDate() - 1);

Simply replace - 1 with - 2, - 3 and so on for the previous seven days.

phreakv6
  • 2,135
  • 1
  • 9
  • 11