Re: formating numbers & date

From: Date: Thu, 05 Dec 2002 01:47:59 +0000
Subject: Re: formating numbers & date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127083@lists.php.net to get a copy of this message
At 11:51 AM 12/5/02 +1100, Justin French wrote:
on 05/12/02 11:37 AM, Rick Widmer (php3@developersdesk.com) wrote: $Hour = substr( $Date, 11, 2 ); if( $Hour ) > 12 { $Hour = $Hour - 12; $AMPM = 'PM'; } else { $AMPM = 'AM'; } echo substr( $Date, 5, 2 ), '/', substr( $Date, 8, 2 ), '/', substr( $Date, 0, 4 ), ' ', $Hour, substr( $Date, 13, 6 ), $AMPM; Isn't this a little simpler? <? $newdate = date('n/j/Y g:i:s a', strtotime($date)); echo $newdate; ?> There's always more than one way to do something I guess :)
Yes, it is simpler to code, but it also takes almost twice as long to run. 1000 iterations with strtotime: 0.2296 seconds
1000 iterations with substr:    0.1308 seconds
Doesn't matter much if you only do it once, but it can add up in a loop. Rick

« previous php.general (#127083) next »