Results 1 to 5 of 5

Thread: convert unix timestamp to date php

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Smile convert unix timestamp to date php

    hi all the problem this time is TIME i put the time in the DB eg "1326995615"

    how do i display it on the page like "9th Jan 2012, 6:46"

    ATM i'm using
    PHP Code:
    '.$row['time'].' 
    to call it back from the mysql_query but it just displays "1326995615"

  2. #2
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    Are you saying you want to know how to show the date in PHP?
    Daba! The Fantage-like website
    Virtual World in progress.
    Out of pure HTML, Javascript, and CSS. Oh, and poorly done Paint images.

  3. #3
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    yes BUT the time is coming from the database not the server clock

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Get the value from the database into a variable. mysql_query(), mysql_fetch_assoc(), etc.

    Then:
    PHP Code:
    date('Y'); //show the current year based on the server's clock
    date('Y',$mydate); //show the year based on the timestamp of $mydate 
    $mydate should be the value from the database. Note that this should be in a timestamp format. For example, right now, it is: 1327001074

    As for date formats, read the php.net page:
    http://php.net/manual/en/function.date.php
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    TwitterRooms (01-19-2012)

  6. #5
    Join Date
    Dec 2011
    Posts
    49
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default

    store it in the db as a DATETIME and use something like this before storing it:
    PHP Code:
    $time date("y/m/d : H:i:s"time()); 
    then just store $time in the column you made with type DATETIME.

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
  •