Jump to content

Converting date string to date?


Padgoi

Recommended Posts

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>.";
 
 
 
?>
Link to comment
https://forums.phpfreaks.com/topic/294732-converting-date-string-to-date/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.