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); 

http://jsbin.com/upeyu/6

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); 

jsfiddle example


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -