Number to Date?

Discussion in 'PHP' started by gerard0986, Mar 25, 2011.

  1. #1
    I got a number (20110325) that I need to convert to a date (03 25 2011), text if possible, but the example I showed is fine too. Problem is, I'm not sure how I'd go about doing this.
     
    gerard0986, Mar 25, 2011 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    
    echo date("m d Y", 20110325);
    
    PHP:
     
    ThePHPMaster, Mar 26, 2011 IP
  3. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That just came up as "08 21 1970".
     
    gerard0986, Mar 26, 2011 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    Thought that was a timestamp.

    
    $date = 20110325;
    $year = substr($date, 0, 3);
    $month = substr($date, 4, 5);
    $day = substr($date, 6, 7);
    
    echo "$month $day $year";
    
    PHP:
     
    ThePHPMaster, Mar 26, 2011 IP
  5. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Came up as "0325 25 201" this time. If it helps, "20110325" is just the year followed by the month then day all in number form.
     
    gerard0986, Mar 26, 2011 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    Lol, sorry didn't get enough sleep last night:

    
    
    <?php
    
    $date = '20110325';
    $year = substr($date, 0, 4);
    $month = substr($date, 4, 2);
    $day = substr($date, 6, 2);
    
    echo "$month $day $year";
    
    
    PHP:
     
    ThePHPMaster, Mar 26, 2011 IP