Re: time from Mysql to php
| From: | Miles Thompson | Date: | Sat, 30 Dec 2000 01:03:20 +0000 |
| Subject: | Re: time from Mysql to php | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-5516@lists.php.net to get a copy of this message | ||
Yes. I spent a bit of time messing about with this, and here's some code from my experiments. $dtAuctionStart is from a table, you'll see it's format below. Sorry if this gets wrapped ...
Some messing about with dates <br>
=============================<br>
<?
echo $dtAuctionStart, "<br>";
echo date ("Y-m-d", $dtAuctionStart ), "<br>";
//$strDate = $dtAuctionStart ;
echo "dtAuctionStart : $dtAuctionStart";
$year = substr ($dtAuctionStart, 0, 4);
$month = substr( $dtAuctionStart, 4, 2 );
$day = substr ($dtAuctionStart, 6, 2 );Echo "dtAuctionStart in m-d -y : $month-$day-$year <br>"; $workdate = getdate( $dtAuctionStart ); echo " Workdate Year:", $workdate["year"],"<br>"; ?> Ereg Stuff <br> ==========<br> <? if (ereg ("([0-9]{4})([0-9]{1,2})([0-9]{1,2})", $dtAuctionStart, $regs)) {
echo "Auction Start: $regs[1]-$regs[2]-$regs[3] <br><br>";} else {
echo "Bad date format. <br>";} //echo gmdate ("Y-m-d", time()), "<br>"; echo date ("M-d-Y", mktime (0,0,0, $month, $day, $year)); // echo date ("M-d-Y", mktime (0,0,0,12,32,1997)); ?> So chew away on this, you'll see that some of the assumptions return very strange dates, as $dtAuctionStart was something like 20001015. I didn't have to use time's in that table, so it never got explored. The tightest interpretation is the "ereg", I find it easier to under stand if I extract substrings. Hope this helps - Miles Thompson At 04:32 PM 12/29/2000 -0800, Kevin McCarthy wrote:
I have several tables that use a date field but for the life of me I can't figure how to use the values to show dates/times in various formats in PHP. The gist of it is, I capture timestamps in a MySQL record as '20001229162800'. I need to use this value to show a time/date in PHP but none of the PHP date/time functions seem to recognize this as a valid date string. Do I need to perform a conversion on this string in order to further format it in display? TIA. Kevin McCarthy Body & Soul http://www.bodynsoul.com -- 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