Page 1 of 1
changing format of timestamp
Posted: Thu Aug 31, 2006 1:51 pm
by bruceg
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?
Posted: Thu Aug 31, 2006 1:57 pm
by Luke
Posted: Thu Aug 31, 2006 2:07 pm
by bruceg
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
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
?>
Posted: Thu Aug 31, 2006 2:09 pm
by Luke
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
?>
Posted: Thu Aug 31, 2006 2:26 pm
by timvw
You can do the formatting while it's still in the dbms... Lookup the DATE_FORMAT function in the MySQL manual...
Posted: Thu Aug 31, 2006 2:29 pm
by pickle
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
...