Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2007
    Thanked 0 Times in 0 Posts

    How can I split a 6 digit number in to 2 separate numbers?

    I have a 6 digit number and I want to split it to 2 separate numbers do you know how can I do this ?
    For example the number 200509 I want to split it in to 2005 and 09.

    Thank you.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Thanked 36 Times in 35 Posts
    like this:
    PHP Code:
    list($year,$month) = str_split(200709,4); 
    Basically, you're wanting to treat the number as a string (which PHP will do for you) and split it after the 4th character, giving a 4-character 'chunk' and a 2-character one. str_split returns an array, so using list() lets you assign the values directly to variables.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


    Posting Permissions

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