Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: how to display MySQL timestamp?

  1. #1
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to display MySQL timestamp?

    ive got database with a date field. when i extracted the data, the format is something like "2003-12-25 23:59:59". how do i "reformat" it to something like
    "Thursday, December 25, 2003 23:59". i tried
    PHP Code:
    echo date("F j Y H:i:s T"$row["date"]); 
    the date/time outputted resets to January 1 1970 00:33:29 UTC.

    tnx.
    Please don't mind me. I am just posting a lot of nonsense.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here you go:
    PHP Code:
    function displayToMk($date){
      
    $date explode(" "$date);
      
    $date[0] = explode("-"$date[0]);
      
    $date[1] = explode(":"$date[1]);
      return 
    mktime($date[1][0], $date[1][1], $date[1][2], $date[0][1], $date[0][2], $date[0][0]);
    }
    echo 
    date("l, F j, Y H:i"displayToMk($row["date")); 
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    By chaining it through strptime() and then back through date():
    Code:
    date('F j Y H:i:s T', strptime('%Y-%m-%d %T', $row['date']));
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Fatal error: Call to undefined function strptime()
    Please don't mind me. I am just posting a lot of nonsense.

  5. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Make sure your server is not running on Windows, or it won't work.

  6. #6
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Schmoopy View Post
    Make sure your server is not running on Windows, or it won't work.
    why won't it work?
    Please don't mind me. I am just posting a lot of nonsense.

  7. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    strptime : Scroll a bit down the page


    Note: This function is not implemented on Windows platforms.

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Mine will work on Windows.

    Although if you're using this on a website and your website isn't hosted on a windows server then go ahead and try Twey's on your site, and not a localhost,
    Jeremy | jfein.net

  9. #9
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Schmoopy View Post
    strptime : Scroll a bit down the page.
    Note: This function is not implemented on Windows platforms.
    it doesn't still explain why it won't work in windows.
    Please don't mind me. I am just posting a lot of nonsense.

  10. #10
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    tried Twey's on Linux.

    how do i implement it now?

    PHP Code:
    $query1 "SELECT date FROM $tablename";
    $result mysql_query($query1) or die('Error, query failed');
    while(
    $row mysql_fetch_array($result)) {
    echo 
    '<td align=right>' date('F j Y H:i:s T'strptime('%Y-%m-%d %T'$row['date'])) . '</td></tr>'"\n";

    the date still reverts back to January 1 1970 not the CURRENT_TIMESTAMP
    Please don't mind me. I am just posting a lot of nonsense.

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
  •