* Thus wrote Duncan Hill ([EMAIL PROTECTED]): > On Friday 19 Sep 2003 10:20, David T-G wrote: > > Hi, all -- > > > > Now it's my turn to ask a simple question, or one that sure sounds like > > it should be... > > > > I have a 14-char date string like "20030917181909" and I need to break it > > into its component parts for a more readable "2003-09-17 18:19:09" view. > > How can I do that? Do I really need to call substr half a dozen > > In perl I'd do something like: > $time =~ m/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/; > $ntime = "$1-$2-$3 $4:$5:$6";
preg_match('/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/', $time, $m); Then $m is an array where the indexes $m[0] = the matched string $m[1] = first () $m[2] = second () ... > > I think php can do that with preg_match, using an array to hold the matches. > > As the other poster said, if this is mysql, let mysql do the work for you :) I suggest this also. Or use the mysql unixtimestamp function to return a uts and format the output with php. In general most of my timestamp fields, in my tables, I create as an INT then just store the Unix timestamp in there. Makes things easier when trying to display things. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php