[mysql/php] parsing a mysql timestamp

Discussion in 'OT Technology' started by RyanL, Jun 3, 2005.

  1. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    [mysql/php] parsing a mysql timestamp SOLVED

    This is starting to mess with me now, maybe one of you guys can enlighten me :rolleyes:.

    I am pulling timestamp from a MYSQL database. When I output it using an echo $human['udate']; I get "20050110" but if I try to say echo substr($human['udate'],4,5); I get 0110.

    I pretty sure that the timestamp isn't actully a string but another format. That being the case I don't know what PHP function I can use to parse it.
     
    Last edited: Jun 3, 2005
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Seems like it works? What's the problem?
     
  3. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    That should only return 01 not 0110. I hacked up a little fix to get the date instead:

    Code:
      $dates = sscanf($human['udate'],'%4s%2s%2s');
      echo $dates[1];
    It's crude but it works. If anyone else knows a better way I'd love to know.
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    5 is the length, not the ending character - in other words ,4,2
     
  5. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    Oh man, I've been at working without a break for way to long... thanks.
     

Share This Page