Formatting timestamp dates retrieved from MySQL
| From: | Miles Thompson | Date: | Wed, 11 Oct 2000 15:10:53 +0000 |
| Subject: | Formatting timestamp dates retrieved from MySQL | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3521@lists.php.net to get a copy of this message | ||
Date formatting has always been ugly, and the MySQL timestamp returns a yyyymmdd,
rather than the mmddyyyy used by the PHP date formatting functions. Is there an
alternative to this, rather ugly, extraction and formatting to get yyyy-mm-dd
rather than a tight yyyymmdd? I know I could do the formatting in the "select",
but as the number of fields we may wish to fetch may vary, I'm happier sticking
with the "*" at present.
Here's the ugly code, dtAuctionStart is one of several timestamp fields:
$sql = "SELECT * FROM item order by cItemId";
$result = mysql_query($sql,$db);
if ( mysql_num_rows( $result) )
{
//bunch of table formatting stuff
while ($myrow = mysql_fetch_array($result))
{
// table formatting stuff surrounds this ...
echo substr( $myrow[dtAuctionStart], 0, 4), "-";
echo substr( $myrow[dtAuctionStart], 4, 2 ), "-";
echo substr( $myrow[dtAuctionStart], 6, 2 );
}
}
Thanks for looking - Miles Thompson