I have a timestamp which displays as the default.
you can check it out here:
http://www.inspired-evolution.com/displ ... esses2.php
the php is <td>{$row['last_updated']}</td>
and last_updated is a column set as 'timestamp' in MySQL.
I would rather it be formatted as just Month, Day. year.
can this be done?
changing format of timestamp
Moderator: General Moderators
Code: Select all
date() getdate()-
bruceg
- Forum Contributor
- Posts: 174
- Joined: Wed Mar 16, 2005 11:07 am
- Location: Morrisville, NC
- Contact:
o.k, so the PHP syntax would be :
$today = date("m.d.y");
where would that need to go in the PHP code pulling from MySQL table
$today = date("m.d.y");
where would that need to go in the PHP code pulling from MySQL table
Code: Select all
echo<<<TABLETOP
<table id="contact_database" cellspacing="0">
<tr>
<th>Name</th>
<th>Primary Telephone</th>
<th>Secondary Telephone</th>
<th>Email Address</th>
<th>Notes</th>
<th>Last Updated</th>
</tr>
TABLETOP;
while ($row = mysql_fetch_assoc($result)) { // Display the data from mysql
echo<<<TABLEDATA
<tr>
<td class="bold">{$row['Name']}</td>
<td>{$row['primary_tel']}</td>
<td>{$row['2ndary_tel']}</td>
<td><a href="mailto:{$row['email_address']}">{$row['email_address']}</a></td>
<td>{$row['Notes']}</td>
<td>{$row['last_updated']}</td>
</tr>
TABLEDATA;
} // End while
echo "</table>";
} // End if
?>bruceg wrote:o.k, so the PHP syntax would be :
$today = date("m.d.y");
where would that need to go in the PHP code pulling from MySQL table
Code: Select all
echo<<<TABLETOP <table id="contact_database" cellspacing="0"> <tr> <th>Name</th> <th>Primary Telephone</th> <th>Secondary Telephone</th> <th>Email Address</th> <th>Notes</th> <th>Last Updated</th> </tr> TABLETOP; while ($row = mysql_fetch_assoc($result)) { // Display the data from mysql $today = date("m.d.y", $row['last_updated']); echo<<<TABLEDATA <tr> <td class="bold">{$row['Name']}</td> <td>{$row['primary_tel']}</td> <td>{$row['2ndary_tel']}</td> <td><a href="mailto:{$row['email_address']}">{$row['email_address']}</a></td> <td>{$row['Notes']}</td> <td>{$today}</td> </tr> TABLEDATA; } // End while echo "</table>"; } // End if ?>
If your date is stored as a MySQL timestamp in the database, it's going to be in a different format that the UNIX timestamp date() expects. To fix this, don't just modify your query a bit:
Code: Select all
...
, UNIX_TIMESTAMP(last_updated) as last_updated
...Real programmers don't comment their code. If it was hard to write, it should be hard to understand.