View Full Version : Splitting String??

10-03-2003, 07:12 PM

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??


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

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

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

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

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

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

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

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

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

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

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

will do just fine

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