...

View Full Version : Splitting String??



SpeedFreak
10-03-2003, 07:12 PM
Hey,

I have a date in the format MM-DD-YYYY contained within the variable $edate.
I want to split it into 3 variables $yyyy, $mm, $dd containing the year, month, and day respectively.

how can i do this??

Thanks

missing-score
10-03-2003, 11:52 PM
$str = explode("-", $date);

list($dd, $mm, $yyyy) = $str;

Keith
10-04-2003, 01:00 AM
Seeing as you called your variable $edate change to:

$str = explode("-", $edate);

list($dd, $mm, $yyyy) = $str;

PrObLeM
10-04-2003, 08:04 AM
you can do it like this too



$edate = explode("-", $edate);
$dd=edate[0];
$mm=edate[1];
$yyyy=edate[2];


the other way works too i figured...hey i mite as welll tell you this way too

missing-score
10-04-2003, 11:31 AM
the list() method does basically what you did, but writing the list function is quicker.

You can find out more about the list function at http://www.php.net/list

ReadMe.txt
10-05-2003, 11:14 AM
u dont really even need the other variable


list($mm,$dd,$yyyy) = explode('-',$edate);

will do just fine

missing-score
10-05-2003, 11:35 AM
very true.

I generally define that as a variable as often i will need it later in the script i am writing, as an array maybe.

but if you need it once, that that would work fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum