How to add Days in variable Date
-
my date is 29/02/2012 and i want to add 1 day to this date the answer should be 01/03/2012. how it is possible.I tried the following way, but not working. var Dte="29/02/2012" var today=new Date(Dte.substring(6,10),Dte.substring(3,5),Dte.substring(0,2)); today.setDate(today.getDate()+1);
-
my date is 29/02/2012 and i want to add 1 day to this date the answer should be 01/03/2012. how it is possible.I tried the following way, but not working. var Dte="29/02/2012" var today=new Date(Dte.substring(6,10),Dte.substring(3,5),Dte.substring(0,2)); today.setDate(today.getDate()+1);
As you are trying to create the date from a specific string, you should realise that the problem is actually at the point that you parse the date. Basically the to indexes in your substrings are out by one. Try:
var today = new Date(Dte.substring(6,9), Dte.substring(3,4), Dte.substring(0,1));
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier