1

can anyone let me know whats wrong with following code

var day = new Date();
var Today = day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate() + ' 00:00:00';
$(xData.responseXML).SPFilterNode("z:row").each(function () {
    var StDate = ($(this).attr("ows_StartDate"));
    var EnDate = ($(this).attr("ows_EndDate"));
    if (Date.parse(Today) >= Date.parse(StDate) && Date.parse(Today) <= Date.parse(EnDate)) {
        alert("Date is in range")
    }

In chrome it works but in IE its give NaN for Date.parse method

2

This is a known issue of IE7/8, see for example here or here:

ECMA-262 r3 does not define any date formats. Passing string values to the Date constructor or Date.parse has implementation-dependent outcome. It is best avoided

You could consider the following solutions:

0

The date format in IE and Chrome differs. Hence it is failing in IE and working in chrome.

You have two options

  1. Check the browser version and act accordingly
  2. Use jQuery date parsing

    $.datepicker.parseDate('yy-mm-dd', Today);
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.