Superman702 Posted August 22, 2011 Share Posted August 22, 2011 Newbie question... I have a form in which I submit time() into an INT on MySQL. After I retrieve that table with the old UNIX Timestamp on it, how do I convert it from .$info['timestamper'] . (which holds the timestamp) into a date and time output? (i.e. 01:05:05 PM 12/25/2010) My Current Code: $mins = time()-60*60*24*3; //Last 72 hours $result = mysql_query("SELECT * FROM messages WHERE `timestamper` > '$mins'"); $num_rows = mysql_num_rows($result); echo "<CENTER><table border cellpadding=3><TR><TH>Message</TH><TH>Sent By</TH><TH>Time</TH></TR>"; while($info = mysql_fetch_assoc($result)){ Print "<tr><TH>".$info['display'] . "</th> <th>".$info['username'] ."<TH>".$info['timestamper'] ."</TH></TR>"; } Link to comment https://forums.phpfreaks.com/topic/245404-converting-time-after-retrevial/ Share on other sites More sharing options...
MasterACE14 Posted August 22, 2011 Share Posted August 22, 2011 date() // Prints something like: Monday 8th of August 2005 03:12:46 PM echo date('l jS \of F Y h:i:s A'); date('h:i:s A m/d/Y',$info['timestamper']); // this will do the trick Link to comment https://forums.phpfreaks.com/topic/245404-converting-time-after-retrevial/#findComment-1260386 Share on other sites More sharing options...
Superman702 Posted August 22, 2011 Author Share Posted August 22, 2011 Worked like a charm. I read it on PHP, but I thought since it was already an existing variable, I couldn't plug it into a date() command. Guess I was wrong. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/245404-converting-time-after-retrevial/#findComment-1260387 Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2011 Share Posted August 22, 2011 Or you could do it directly in the query. SELECT FROM_UNIXTIME(timestamper, '%h:%i:%s %p, %m/%e/%y') AS formatted_date, * FROM messages WHERE `timestamper` > '$mins' Link to comment https://forums.phpfreaks.com/topic/245404-converting-time-after-retrevial/#findComment-1260393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.