...

View Full Version : parseInt() problem



ellisd5
07-03-2003, 12:51 PM
I have a string which is always in this format dd/mm/yyyy

i do the following to retrieve the month :-

var month = parseInt(sDate.substring(3, 5));

however there is a problem with this.

I have alerted the values out of sDate.substring(3, 5) and month when i enter different values :-



sDate.substring(3, 5) | month
------------------------------------------
01 | 1
02 | 2
03 | 3
04 | 4
05 | 5
06 | 6
07 | 7
08 | 0
09 | 0
10 | 10
11 | 11
12 | 12


Why is 08, and 09 being parsed to a 0 ????????
how can I fix this?
Really need to sort this asap so any help would be great.

thanks, Dale

ellisd5
07-03-2003, 01:49 PM
I've solved it,

If anyone has read it my above post and been stumped the reason is here:

http://www.marshy.com/members/dtjmarsh/home.nsf/0/D83E9AD38DB2A21B88256BB40021B9FD?OpenDocument

beetle
07-03-2003, 02:47 PM
Ya, I got in the habit of using parseInt( num, 10 ) a while ago.

Glad you found your answer.

Roy Sinclair
07-03-2003, 02:48 PM
var month = parseInt(sDate.substring(3, 5),10);

And now the answer is here too.

Actually a search of this forum would have also brought up several threads with the answer:

http://www.codingforums.com/showthread.php?s=&threadid=18981&highlight=radix is one of them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum