SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    formatting timestamp

    I have a timestamp field "mtime" with this data: 20060624191848
    I formatted it like this:

    PHP Code:
    $format_date date('M d\t\h\, Y \a\t h\:i a'strtotime($row['mtime'])); 
    and I get this as the output:
    Dec 31th, 1969 at 06:59 pm

    What's wrong with my code?

  2. #2
    SitePoint Enthusiast ssx-gun's Avatar
    Join Date
    Sep 2002
    Location
    Strongsville, OH
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, Im a little off today. See below.
    Last edited by ssx-gun; Jul 6, 2006 at 20:20.
    PHP: Pills Help People
    ---
    weird-one.com


  3. #3
    Evil Genius MilchstrabeStern's Avatar
    Join Date
    Nov 2003
    Location
    Arizona
    Posts
    1,131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure strtotime is giving you the correct timestamp? My guess is not.

    I get this:
    1151198328 Jun 24 2006

    with:
    PHP Code:
    <?php

    $time 
    strtotime('20060624191848');
    echo 
    $time;
    echo 
    "\n\r".date('M d Y',$time);
    ?>
    And this:
    1151198328 Jun 24 h, 2006 a 07:18 pm

    with:
    PHP Code:
    <?php

    $time 
    strtotime('20060624191848');
    echo 
    $time;
    echo 
    "\n\r".date("M d\t\h\, Y \a\t h\:i a",$time);
    ?>
    Check the database.
    ]

  4. #4
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ssx-gun
    if you use \ you need to do \\ so it will display how you want it.
    You mean I should change my code to:

    PHP Code:
     $format_date date('M d\\t\\h\\, Y \\a\\t h\\:i a'strtotime($row['mtime'])); 
    ?
    I just tried that but it did not help.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MilchstrabeStern
    Are you sure strtotime is giving you the correct timestamp? My guess is not.

    I get this:
    1151198328 Jun 24 2006

    with:
    PHP Code:
     <?php
     
     $time 
    strtotime('20060624191848');
     echo 
    $time;
     echo 
    "\n\r".date('M d Y',$time);
     
    ?>
    And this:
    1151198328 Jun 24 h, 2006 a 07:18 pm

    with:
    PHP Code:
     <?php
     
     $time 
    strtotime('20060624191848');
     echo 
    $time;
     echo 
    "\n\r".date("M d\t\h\, Y \a\t h\:i a",$time);
     
    ?>
    Check the database.
    hmm, no, I get something different when I use your code, this is my output:

    -1 Dec 31 1969

    and

    -1 Dec 31 h, 1969 a 06:59 pm


    What is the problem and what does it mean? I just got the date format code from someone else, maybe there is a better way to format the date, without using strtotime?

  6. #6
    SitePoint Enthusiast ssx-gun's Avatar
    Join Date
    Sep 2002
    Location
    Strongsville, OH
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm... strtotime() = bad

    PHP Code:
    <? 
    $result
    =mysql_query("SELECT UNIX_TIMESTAMP(TIME) AS FORMATED_TIME FROM EXAMPLE_TABLE"); 
    $FORMATED_TIME=mysql_result($result,0,"FORMATED_TIME"); 
    $date=date("m-d-Y H:i:sa",$FORMATED_TIME); 
    echo 
    "$date"
    ?>
    That is for MySQL which is what it looks like you are using when you did the $row comment.

    Code from:
    http://php.codenewbie.com/articles/p...mp-Page_1.html
    PHP: Pills Help People
    ---
    weird-one.com



Bookmarks

Posting Permissions

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