0

I am extracting the day, month, and year from a date string by calling split to get each section of the string, and then parsing them individually with parseInt. This is working in Chrome and Edge, but it is not working correctly in IE11 Enterprise Mode.

This is how the data is populating. But the issue is in 03. It should return as 3. If I run the same code in Chrome and Edge, it returns 3 rather than 03.

Can someone help me resolve this?

var inputDateText = $(this).val(); //30/03/2021
var splitComponents = inputDateText.split('/');  //[30,03,2021]

if (splitComponents.length > 0) {
    var day = parseInt(splitComponents[0]); //30
    var month = parseInt(splitComponents[1]); //03
    var year = parseInt(splitComponents[2]); //2021
nbrooks
  • 18,126
  • 5
  • 54
  • 66
user10216769
  • 33
  • 1
  • 7
  • `parseInt` returns the number value of the string given. A number does not have a leading zero. Also, it requires a radix if not in strict mode, especially with strings starting with zeros. – Heretic Monkey Mar 30 '21 at 21:34
  • Hi @HereticMonkey, the same works fine in Chrome and Edge but not in Enterprise mode. I will get return `3` in Chrome but `03` in enterprise mode.Can you please provide solution for this. – user10216769 Mar 30 '21 at 21:37
  • I know this answer will be very basic, but can you try if (splitComponets[1].charAt(0) == "0") { splitComponets[1] = splitComponets[1].replace("0",""); } – Reşat Karaçöl Mar 30 '21 at 21:37
  • Use a radix, as the duplicate mentions. However, I tried this code in Enterprise mode in IE11, and was unable to reproduce the situation. I get `3` for `month`. – Heretic Monkey Mar 30 '21 at 21:57

0 Answers0