Re: AW: [PHP-DB] Formatting timestamp dates retrieved from MySQL

From: Date: Wed, 11 Oct 2000 17:31:03 +0000
Subject: Re: AW: [PHP-DB] Formatting timestamp dates retrieved from MySQL
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-3527@lists.php.net to get a copy of this message
Tobias, Never thought of it! Regular expressions aren't part of my background, so they don't come to mind. I'll try it and let you know. Thanks - Miles Tobias Wolff wrote: > Have you checked the regular expression functions? > > I don't have the exact syntax at hand now, but it might be something like: > > if(ereg("([0-9]{2,4})-([0-9]{2})-([0-9]{2})", $date, $parts)) { > $new_date = $parts[3]."-".$parts[2]."-".$parts[1]; > } > > -----Ursprüngliche Nachricht----- > Von: Miles Thompson [mailto:milesthompson@sprint.ca] > Gesendet: Mittwoch, 11. Oktober 2000 17:11 > An: php-db@lists.php.net > Betreff: [PHP-DB] Formatting timestamp dates retrieved from MySQL > > 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 > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#3527) next »