[Solved] JavaScript Future Date Failing


The following section of your code isn’t quite right:

var testDate = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );
var testMonth=testDate.getMonth()+1;
if  (testMonth<10)
{
   testMonth = "0"+testDate.getMonth();   // change this line
} 

When you initialise testMonth you remember to add 1 because .getMonth() returns a zero-based month, but then inside your if test you use .getMonth() again without adding 1. You should change that to testMonth = "0" + testMonth;.

(Also, not the problem, but when you create temp there is no point initialising it to a new array when on the next line you assign it to something else.)

Sorry, I have to go so I don’t have time to look for any other issues in your code.

2

solved JavaScript Future Date Failing