Convert SYSDATE() into something more viewable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Convert SYSDATE() into something more viewable

Post by Cooperman »

Hi there,

Can anyone tell me how I convert the SYSDATE() format 2008-06-04 21:10:01
into something more viewable like:

04/06/2008 21:10:01

in php?

I am requesting this from the DB in a loop but I need to view "$row["logged"] " as 04/06/2008 21:10:01
<?
$result = mysql_query("SELECT topic, logged FROM forum order by logged desc");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
echo("<tr><td>&nbsp;</td><td>" . $row["topic"] . "</td><td>" . $row["logged"] . "</td></tr>");

}

?>
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Convert SYSDATE() into something more viewable

Post by nowaydown1 »

You can use the php date function (http://www.php.net/date):

Code: Select all

 
date("m/d/Y H:i:s", strtotime($row["logged"])); 
 
Alternatively, you could use some of the SQL date based manipulation stuff to just have the database do your format conversion for you.
Post Reply