Padgoi Posted February 19, 2015 Share Posted February 19, 2015 Hey all, So I have this very small script that is simply pulling information from a dbase and displaying it. The problem is the date in the dbase is stored in a string (it looks like 1424375795 or something). I need to convert that number to the date and time. Here's the code: <?php //query the database $query = mysql_query("SELECT * FROM topics ORDER BY last_post"); //fetch the results / convert results into an array WHILE($rows = mysql_fetch_array($query)): $topic_id = $rows['last_post']; $topic_title = $rows['title']; $reply_author = $rows['last_poster_name']; $reply_time = $rows['last_post']; endwhile; echo "The last post was made in <font color='blue'>$topic_title</font> by <font color='red'>$reply_author</font> at <font color='green'>$reply_time</font>."; ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 19, 2015 Share Posted February 19, 2015 $rows['last_post'] contains a timestamp you can pass it as the second argument to date to convert it to a english readable format. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted February 19, 2015 Author Share Posted February 19, 2015 Can you please help a bit more? My PHP knowledge is very limited. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2015 Share Posted February 19, 2015 looks like a unix time value Try SELECT FROM_UNIXTIME(last_post) FROM topics Quote Link to comment Share on other sites More sharing options...
requinix Posted February 19, 2015 Share Posted February 19, 2015 (Threads merged.) Quote Link to comment Share on other sites More sharing options...
Padgoi Posted February 19, 2015 Author Share Posted February 19, 2015 looks like a unix time value Try SELECT FROM_UNIXTIME(last_post) FROM topics It's a timestamp. I just don't know how to incorporate it into my current code. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 19, 2015 Share Posted February 19, 2015 It's a timestamp. I just don't know how to incorporate it into my current code. Did you try that query format that Barand provided? It should return the value in a formatted string: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime Quote Link to comment Share on other sites More sharing options...
rwhite35 Posted February 20, 2015 Share Posted February 20, 2015 you can try this too. echo date('Y-m-d H:i:s', $rows['last_post']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.