0

I have this Example which does not work in IE, but works in all other browsers can you take a look. What is the problem here? Note: This is a continuation of this

Updated : The problem is my example works in chrome but gives NaN in IE 8 and firefox 6.

My Code

var cellvalue="2011-08-18 11:49:01.0 IST";
var firstDate = new Date();
var secondDate = cellvalue.substring(0, cellvalue.length-4);
alert(diffOf2Dates(firstDate,secondDate));
function diffOf2Dates(todaysDate,configDate)
{
/*var udate="2011-08-18 11:49:01.0";
var configDate=new Date(udate);*/

var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = todaysDate; // Todays date
var secondDate = new Date(configDate);

var diffDays = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));


return Math.ceil(diffDays);
}

Note: My format

2011-08-19 11:49:01.0 IST
Community
  • 1
  • 1
AabinGunz
  • 12,109
  • 54
  • 146
  • 218

1 Answers1

2

the problem is the fomat of the date: ie doesnt support the way other browsers do.. run this: jsfiddle.net/vQnHz/7

it is recommended you use this constructor: var variable = new Date(year, month, day, hours, minutes, seconds, milliseconds2)

Baz1nga
  • 15,485
  • 3
  • 35
  • 61
  • My format is fixed, I cannot change it unless after getting it into some variable is there a way I can put it in some accepted format? – AabinGunz Aug 22 '11 at 06:21
  • 1
    Check with this URL http://stackoverflow.com/questions/1856199/use-javascript-to-parse-time – Naga Harish M Aug 22 '11 at 06:30