PHP Timestamp

Discussion in 'PHP' started by Weirfire, May 26, 2006.

  1. #1
    I have the following code;

    $date = date("d/m/y G:i","20060526154458");
    echo $date;

    which when I print it gives the date as

    19/01/38 3:14

    I'm obviously doing something daft. Any ideas?
     
    Weirfire, May 26, 2006 IP
  2. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #2
    Can you tell what you exactly you want to do?
     
    Nikolas, May 26, 2006 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah Steve, would be handy to know what you;re actually trying to accomplish because that code is just fine... You're getting there what you are asking for.
     
    T0PS3O, May 26, 2006 IP
  4. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    is this what you are trying to do?
     $date = date("d/m/y G:i",mktime(15,44,58,05,26,2006));
    echo $date;
    Code (markup):
     
    rosytoes, May 26, 2006 IP
  5. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #5
    Yes Weirfire's code is doing what it's supposed to but I believe what he's referring to is the fact that the date it's outputting isn't what he's expecting. The problem is his "timestamp" is not a valid one (unix timestamps only have 10 digits), so the date is wrong since the timestamp is out of range.
     
    sketch, May 26, 2006 IP
  6. Young Twig

    Young Twig Peon

    Messages:
    27
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try this:

    $date = date("d/m/y G:i", strtotime("20060526154458"));
    echo $date;
    PHP:
    Returns: 26/05/06 15:44
     
    Young Twig, May 26, 2006 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    Thanks Young Twig. Thats exactly what I was looking for.

    Sorry guys... I should have specified what output I was trying to achieve.
     
    Weirfire, May 27, 2006 IP
  8. Bartbos

    Bartbos Peon

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you're getting that number from DB, you can just do SELECT UNIX_TIMESTAMP(datecolumn) AS datecolumn and don't have to do the strtotime.
     
    Bartbos, May 27, 2006 IP