This is the P2PU Archive. If you want the current site, go to www.p2pu.org!
You haven't posted any discussions yet.
OK, I've rewritten this a bunch of different ways and keep getting completely the wrong date! I'm sure it's something really obvious but I fear I've been staring at this way too long now..
Can anyone see where I'm going wrong and point me in the right direction?
function extractDate(paragraph) {
return new Date(Number(paragraph.slice(11, 4)),
Number(paragraph.slice(8, 2) - 1),
Number(paragraph.slice(5, 2)));
}
show(extractDate("died 27-04-2006: Black Leclere"));
>Thu Nov 30 1899 00:00:00 GMT+0000 (GMT Standard Time)
When you're slicing, you need to add in your beginning spot to the end spot. So instead of calling slice(11,4), call it like slice(11,11+4). The entire solution follows:
function extractDate(paragraph) {
return new Date(Number(paragraph.slice(11, 11+4)),
Number(paragraph.slice(8, 8+2) - 1),
Number(paragraph.slice(5, 5+2)));
}
show(extractDate("died 27-04-2006: Black Leclere"));
Thank you - I knew it would be something simple! +1 rep for dysert. :-)