Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date constructor returns NaN in IE, but works in Firefox and Chrome

I'm trying to build a little calendar in JavaScript. I have my dates working great in Firefox and Chrome, but in IE the date functions are returning NaN.

Here is the function :

function buildWeek(dateText){     var headerDates='';     var newDate = new Date(dateText);      for(var d=0;d<7;d++){         headerDates += '<th>' + newDate + '</th>';         newDate.setDate(newDate.getDate()+1);     }                             jQuery('div#headerDates').html('<table><tr>'+headerDates+'</tr></table>'); } 

dateText is the Monday of the current week which is actually set in php in the format of 'm, d, Y', e.g. "02, 01, 2010".

like image 315
pedalpete Avatar asked Feb 02 '10 06:02

pedalpete


1 Answers

From a mysql datetime/timestamp format:

var dateStr="2011-08-03 09:15:11"; //returned from mysql timestamp/datetime field var a=dateStr.split(" "); var d=a[0].split("-"); var t=a[1].split(":"); var date = new Date(d[0],(d[1]-1),d[2],t[0],t[1],t[2]); 

I hope is useful for someone. Works in IE FF Chrome

like image 193
Qlimax Avatar answered Sep 19 '22 14:09

Qlimax