Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts

    parseInt() problem

    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 :-

    Code:
             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

  • #2
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I've solved it,

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

    http://www.marshy.com/members/dtjmar...D?OpenDocument

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ya, I got in the habit of using parseInt( num, 10 ) a while ago.

    Glad you found your answer.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/showthre...ighlight=radix is one of them.
    Last edited by Roy Sinclair; 07-03-2003 at 02:50 PM.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •