-1

How to subtract date with day..

eg;- curdate: 20130207 Orginal date has to be : 20130206,2010205, 20130204,..., 20130201, 20130131, 20130130,etc..

How to do this with javascript (or the calculator step if you know Pentaho)?

Say, I want go all the days going back for 90 days.

Puzzled.

dat789
  • 1,923
  • 3
  • 20
  • 26

2 Answers2

0

Use setDate and getDate:

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

Or, for all your 90 days:

d = new Date();
for (i = 1; i <= 90; i++) {
   d.setDate(d.getDate() - 1);
   console.log(i+" days ago: "+d);
}
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
0

Use something like:

var d1 = new Date(2012, 1, 6) // date(year, month - 1, day)
days= -90; //# of days
var d2 = new Date(d1.setDate(d1.getDate() + days));

DEMO: http://jsfiddle.net/dirtyd77/qZWJE/

Dom
  • 38,906
  • 12
  • 52
  • 81