Quick programming question (php)

Discussion in 'OT Technology' started by o2, Feb 5, 2008.

  1. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    I have a date stored as YYYY-MM-DD, how would I split that up into 3 variables, each one containing year, month and day (respectively)?
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    Code:
    $date = "2008-02-02";
    list($year, $month, $day) = split('[-]', $date);
    Puts them into the $year, $month, and $day variables.
     
  3. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    Thank you sir!
     
  4. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    Split is great if you want to use regex, but if you need something more simple, use explode as it uses a string. And use single quotes around your strings unless you have a variable in them. Extra processing time wasted there.

    Code:
    $date = '2008-02-02';
    list( $year, $month, $day ) = explode( '-', $date );
    
     
  5. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    Ahhh cool. I shall use this instead I guess.
     
  6. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    +1 explode
     

Share This Page