View Full Version : convert unix timestamp to date php
TwitterRooms
01-19-2012, 05:58 PM
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
'.$row['time'].'
to call it back from the mysql_query but it just displays "1326995615"
[Nicolas]
01-19-2012, 06:41 PM
Are you saying you want to know how to show the date in PHP?
TwitterRooms
01-19-2012, 06:50 PM
yes BUT the time is coming from the database not the server clock
djr33
01-19-2012, 07:24 PM
Get the value from the database into a variable. mysql_query(), mysql_fetch_assoc(), etc.
Then:
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
baconDelta
01-26-2012, 09:40 PM
store it in the db as a DATETIME and use something like this before storing it:
$time = date("y/m/d : H:i:s", time());
then just store $time in the column you made with type DATETIME.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.