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.

Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.