0

I get NaN error when I try to parse date from JSON in my Javascript

Format of date: "2015-02-10T23:01:00.000Z"

This is my code that works in Chrome but not in IE8:

            var sdate = new Date(entry.startDate);
            var sdateMonth = sdate.getMonth() + 1;
            var sdateDay = sdate.getDate();
            var edate = new Date(entry.endDate);
            var edateMonth = edate.getMonth() + 1;
            var edateDay = edate.getDate();
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
Timvdb92
  • 63
  • 9
  • https://msdn.microsoft.com/en-us/library/ie/ff743760%28v=vs.94%29.aspx IE supports ISO Date format from version IE9+. So you either use some library (like moments.js) or change date string format. – Alexey Ten Feb 11 '15 at 09:39
  • It has to work in IE8 :s – Timvdb92 Feb 11 '15 at 09:44
  • possible duplicate of [Javascript JSON Date parse in IE7/IE8 returns NaN](http://stackoverflow.com/questions/11020658/javascript-json-date-parse-in-ie7-ie8-returns-nan) –  Feb 11 '15 at 10:46

1 Answers1

0

Not a direct solution yet reasonable suggestion in my opinion: Moment.js this will cover datetime parsing and manipulation for you.

Tom Hofman
  • 518
  • 5
  • 19