What's wrong with this javascript date parsing? Why does js hate the number 8?
date, javascript, jquery, parsing
Solution
`08` is considered as an (invalid) octal literal by default.
You have to explicitly specify the radix in your call to parseInt() in order for this token to be considered as a decimal (base 10) number:
$("#debug").append(parseInt(date.substr(5, 2), 10) + " / ");
Problem
I've got an object containing dates in the format `YYYY-MM-DD`. I'm extracting the various year, month and day integers so I can send them to a different `API`. Here's an example of my method, using `substr()` Demo: http://jsfiddle.net/AppSynergy/tELsw/ OK, it works. OH NO! - it doesn't - not quite.. What's wrong with the 3rd element, where the "08" in 8th April decides to be 0 instead? If I change "08" to another integer e.g. "03", it's fine. But "08" causes issues.. This one is driving me crazy -- what's wrong? If you can spot it, you deserve ice-cream.