SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot croman's Avatar
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to figure out Timestamp

    I found a little tutorial that had a snippet code to pull out a timestamp and then display it correctly, however I am not having any luck unfortunately.

    I have a field (Time) in a Table (EXAMPLE_TABLE) that has the following info in it:
    20040901153558


    I have the following query:

    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";

    It is giving me the following result:
    01-01-1970 00:00:00am


    Any ideas?

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Aug 2004
    Location
    mishawaka, in
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may help you:

    The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). On windows this range is limited from 01-01-1970 to 19-01-2038.
    The reason you are getting 01-01-1970 is because your Win-32 system can't handle an integer that is bigger than 32 bits.

  3. #3
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Windows explanation is interesting, but doesn't explain why a timestamp from today wouldn't work.

    I replicated the process in two steps:

    One:
    Code:
    mysql> SELECT UNIX_TIMESTAMP(20040901153558);
    +--------------------------------+
    | UNIX_TIMESTAMP(20040901153558) |
    +--------------------------------+
    |                     1094067358 |
    +--------------------------------+
    Two:
    PHP Code:
    echo date("m-d-Y H:i:sa",1094067358);
    // this displays 09-01-2004 15:35:58pm 
    My suggestion would be to see if the value you are getting from MySQL differs from 1094067358.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  4. #4
    SitePoint Member
    Join Date
    Aug 2004
    Location
    mishawaka, in
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    He who doesn't fully read, answers wrong (my bad)

    Ah. I looked at the code a bit to quick. I thought he was trying to use the timestamp 20040901153558. My bad. If you are at the beginning of the project, just change the way you store the time, just save it as a timestamp instead of 20040901153558. Then you can use php for the date conversions rather than mysql.

  5. #5
    SitePoint Zealot croman's Avatar
    Join Date
    Apr 2003
    Location
    Minneapolis, MN
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone..

    I changed the code to

    Code:
    $result=mysql_query("SELECT UNIX_TIMESTAMP(Time) FROM EXAMPLE_TABLE"); 
    $FORMATED_TIME=mysql_result($result,0
    
    $date=date("m-d-Y H:i:sa",$FORMATED_TIME); 
    
    echo "$date";
    And it worked perfectly


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
  •