Wednesday, 24 May 2017

Not able to split a string in Node.js

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)



via writeToBhuwan

No comments:

Post a Comment