Javascript String changes when Converted to Date() -


i have run weird problem.

i have 2 javascript string variables data 2 text boxes.

the third string pulled table cell. however, when converted javascript date() date changes. have no idea why happening.

i comment code explain going on.

//get text first textbox (from date) var valuefrom = document.getelementbyid('selected-submitteddate-from').value;                 //convert string right format                               var formatdatestring = function (unformatted) {                     var parts = unformatted.split('-');                     return parts[1] + '/' + parts[2] + '/' + parts[0];                 };                 var formatteddatefrom = formatdatestring(valuefrom);      //get text second textbox (to date) //convert string right format                 var valueto = document.getelementbyid('selected-submitteddate-to').value;                 var formatdatestringto = function (unformatted) {                     var parts = unformatted.split('-');                     return parts[1] + '/' + parts[2] + '/' + parts[0];                 };                 var formatteddateto = formatdatestringto(valueto);  //just make new variables , set formatted dates them                 // date from, date                 var datefrom = formatteddatefrom;                 var dateto = formatteddateto;  //get table row, table cell,                 var tablerow = document.getelementbyid("applicant_data");                 var tablecells = tablerow.getelementsbytagname("td");                  // table cell[6] date                 var check = tablecells[6].innertext;                 //convert string (i think anyways?)                 var datecheck = check.tostring();           // remove slashes in strings                 var d1 = datefrom.split("/");                 var d2 = dateto.split("/");                 var c = datecheck.split("/");          //log testing                 console.log(d1);                 console.log(d2);                 console.log(c);          //convert strings dates , set them new variable                 var = new date(d1[2], d1[1]-1, d1[0]);                 var = new date(d2[2], d2[1]-1, d2[0]);                 var check1 = new date(c[2], c[1]-1, c[0]);           //log them out again                 console.log(from);                 console.log(to);                 console.log(check1); 

the issue output, @ this:

["03", "04", "2014"] ["03", "05", "2014"] ["08", "19", "2013"] thu apr 03 2014 00:00:00 gmt-0400 (eastern daylight time) sat may 03 2014 00:00:00 gmt-0400 (eastern daylight time)  //this date below should august 19 2013...... tue jul 08 2014 00:00:00 gmt-0400 (eastern daylight time) 

how happening?!???!? third date literally changing.

19 converted month instead of 8 , looks of it, a modulo operation. 19%12 = 7 subtraction: 19 - 12 = 7 hence july. may want rearrange date, otherwise it's same case first 2. in other words, swap month , day in new date call.

more details+(correction on earlier mistake):

var check1 = new date(c[2], c[1]-1, c[0]);

in code above, need swap last 2 have:

var check1 = new date(c[2], c[0]-1, c[1]);

the function expecting give year, month , day.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -