javascript - Adding/Subtracting days from a date doesn't change the year/month correctly -
if have date 2011-01-02
, subtract 7
days date should give me 2010-12-26
, instead gives me 2011-01-26
?
see js below verify link:
var date = new date('2011','01','02'); alert('the original date '+date); var newdate = new date(date); newdate = newdate.setdate(newdate.getdate() - 7); var nd = new date(newdate); alert('the new date '+nd);
i think meant this: (working perfectly)
var date = new date('2011','01','02'); alert('the original date '+date); var newdate = new date(date); newdate.setdate(newdate.getdate() - 7); var nd = new date(newdate); alert('the new date '+nd);
Comments
Post a Comment