Jump to content

php timestamp conversion


Phpfr3ak

Recommended Posts

I find it preferable to use MySQL's DATE_FORMAT() function and have them formatted and ready to go.

 

SELECT DATE_FORMAT(time_field, '%b %e, %H:%s') AS formatted_time FROM table

 

With the field alias AS formatted_time, the formatted date/time would be available in the ['formatted_time'] element of your associative array.

You still need to extract the results from the query resource with mysql_fetch_assoc(), and assuming you're expecting more than one result, it would be in this format:

 

$sql = "SELECT DATE_FORMAT(timestamp, '%b %e, %H:%s') AS formatted_time FROM ledger";
$que = mysql_query($sql) or die(mysql_error());
while( $array = mysql_fetch_assoc($que) ) {
     echo "<tr><td class='lil1'>$array[formatted_time]</td>";
}

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.