Re: breaking a string into chunks

From: Date: Fri, 19 Sep 2003 10:10:31 +0000
Subject: Re: breaking a string into chunks
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-163115@lists.php.net to get a copy of this message
Duncan, et al -- ..and then Duncan Hill said... % % On Friday 19 Sep 2003 10:20, David T-G wrote: % > % > 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"; Hmmm... That's not a bad idea. % % I think php can do that with preg_match, using an array to hold the matches. Yep. % % As the other poster said, if this is mysql, let mysql do the work for you :) Well, I would, but this has already been pulled out by another call for its own use. I'm being clever and reusing the data I have rather than making an extra DB query. Gee, see how much time it's saving me? ;-) It also happens that I don't know how to have mysql format it for me as I would like were I to make said second query -- but that's only temporary. Thanks & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

« previous php.general (#163115) next »