-1

I am trying to send a request to node server. The browser sends the date in mm/dd/yyyy format which is handled by server in the below manner.

    var endDate;
    if (req.query.endDate) {
        endDate = new Date(req.query.endDate);
    }

This works just fine in chrome and other browsers except IE.

In IE11, it encodes the date to '?5?/?24?/?2017' from '5/24/2017' for some reason. To fix this I am trying to do this :

    var endDate;
    if (req.query.endDate) {
        endDate=req.query.endDate.toString().trim();
        endDate=endDate.toString().split('?').join('');
        console.log('Log',endDate);
        endDate = new Date(endDate);
    }

Expected result is '5/24/2017' But it does not work.

When i see the split('?') for '?5?/?24?/?2017' in the logs it shows ['?5?/?24?/?2017'] as the result. Why is it not splitting the string?

Am I doing Anything wrong? Node version : 4.3.2(using NVM) Code

Error

Code

writeToBhuwan
  • 3,233
  • 11
  • 39
  • 67

1 Answers1

1

In your case "?" could be not the question mark, assume, some UTF-8 symbol.

It can be used the date formatting itself:

var endDate = new Date(req.query.endDate);
endDate.toLocaleDateString()

or

var endDate = new Date(req.query.endDate);
(endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getFullYear();

or regexp approach:

req.query.endDate.toString().match(/[0-9]+/g); // [month, date, year]
FieryCat
  • 1,875
  • 18
  • 28