I've got the following which works fine in Chrome:
function funLoad(str1,str3,str4)
{
var dym1 = str1.split("/");
var d=new Date();
var dym2 = d.getMonth() + 1 + " " + d.getDate() + " " + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":00";
//var dym2 = "6 10 2013 09:00:00";
var start = Date.parse(dym1[1] + " " + dym1[0] + " " + dym1[2] + " " + str3 + ":" + str4 + ":00");
var end = Date.parse(dym2);
return (start-end) / (1000*60*60);
}
$("#btn1").click(function(event){
alert(funLoad($("#txt1").val(),$("#ddlHourTime").val(),$("#ddlMinuteTime").val()));
});
Here is a jsFiddle: http://jsfiddle.net/oshirowanen/QTVWd/6/
When I run this in IE8, I just get alerted with NaN
.
To simplify a little bit the error is because the format used by IE to store dates is not the same used by, for example, Chrome (and the one you're using to manually parse and format the date). It's allowed by the standard, what is required is the browser can parse the format produced by itself (see §15.9.4.2).
Usually to work directly with date format is not a good idea, not only because browser specific implementation but because of globalization (this is especially true for a web application with a virtual world wide audience). In practice what I mean is DO NOT EVER DO something like this (in this post I try to explain the reasons):
or this:
Few exceptions to this rule:
Date.parse()
) because it's locale and browser dependent.The only format you're sure every browser (that supports ECMAScript 5) will read is ISO 8601
YYYY-MM-DDTHH:mm:ss.sssZ
(see §15.9.1.15) so in your case you should change your custom parsing/formatting to that. For older browser there is not a clear rule (that's why we need a library). The standard says at §15.9.4.2 that:(emphasis is mine)
Take a look to this and this posts on SO for other details (or this little tutorial about dates).
What I suggest, if you work with dates across browsers and locales, is to use a good library to abstract all this details. I found this one is pretty strong and easy to use. If you want a widely used almost complete library take a look to moment.js too.
Looks like that format is not supported in IE