Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: how to display MySQL timestamp?

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

    Default

    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]); 

    $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'displayToMk($row["date")) . '</td></tr>'"\n"

    Jeremy | jfein.net

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

    Default

    @Schmoopy

    Quote Originally Posted by Schmoopy View Post
    Make sure your server is not running on Windows, or it won't work.
    Quote Originally Posted by jr_yeo View Post
    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
    dont worry Nile, yours works just fine in both platforms
    Please don't mind me. I am just posting a lot of nonsense.

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

    Default

    I'm saying - use mine, not one that will work on all servers.

    By any change do you know if your server is hosted on Windows, Linux, or Mac?
    Jeremy | jfein.net

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

    Default

    i did use your code

    m localhost on Windows and Linux.

    but does it matter if mine is locally hosted and need to be on remote host/server?
    Please don't mind me. I am just posting a lot of nonsense.

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

    Default

    Sorry, I got the arguments the wrong way around. It should be date('F j Y H:i:s T', strptime($row['date'], '%Y-%m-%d %T')).

    it doesn't still explain why it won't work in windows.
    Well, yes, it does. The function isn't implemented there, therefore it can't.

    A better solution to this would be to implement strptime() in PHP if it doesn't already exist, though it seems a bit tedious. It's fairly simple to parse out the assorted values, but then there are about fifty different scales to apply, which has to be done manually as far as I can see.

    Edit: I see that strptime() is not a strict inverse of strftime(). While strftime() takes a time_t/timestamp, strptime() returns a struct/array of various values. This does make it easier to implement, but unfortunately it also means that it's less useful for your situation.
    Last edited by Twey; 02-01-2009 at 06:07 PM.
    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!

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

    Default

    Warning: date() expects parameter 2 to be long, array given in my filename.php
    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
  •