Hello, I was just playing around with some database display information. I have a variable that I should tell you what they are first.
-- The $e[array] is an events database call
-- The others are pretty explanatory.
Anyways I wanted to take a DATE TIME entry in the database. It looks like so YEAR/MO/DA 08:08:00 PM. I wanted this to do different things, and figured you could make some use of it. I plan to make this more efficiant with time, but pretty simply does what I needed for the time being.
I wanted YEAR-MO-DA 08:08:00 PM to first of all, leave out the time. So let's count how many chars are in YEAR/MO/DA
Y1-E2-A3-R4-|-5|-M6-07-|-8|-D9-A10 .. 10 characters in the 'needed' string. So let's limit the length of $datestart and $dateend.
PHP Code:
$datestart = substr($e['datestart'], 0, 10); // Show only the date
$dateend = substr($e['dateend'], 0, 10); // Show only the date
substr does all the work there..
Now, it's showing the date only. I needed it to remove the -'s so I did... and replaced them with /.
PHP Code:
$reg_ex = "\-"; // Look for what?
$replace_word = "/"; // Replace with what?
$datestart = ereg_replace($reg_ex, $replace_word, $datestart);
$dateend = ereg_replace($reg_ex, $replace_word, $dateend);
Now that I have replaced the dashes with slashes I needed to completely chang the format of YEAR/MO/DA to MO/DA/YEAR so let's go ahead and use explode to do that.
PHP Code:
$datestart_pieces = explode("/", $datestart);
$year = $datestart_pieces[0];
$month = $datestart_pieces[1];
$day = $datestart_pieces[2];
$datestart = $month.'/'.$day.'/'.$year;
$dateend_pieces = explode("/", $datestart);
$year = $dateend_pieces[0];
$month = $dateend_pieces[1];
$day = $dateend_pieces[2];
$dateend = $month.'/'.$day.'/'.$year;
Then call show what we've done.
PHP Code:
echo $datestart.' - '.$dateend;
This all looks like this.
PHP Code:
$datestart = substr($e['datestart'], 0, 10); // Show only the date
$dateend = substr($e['dateend'], 0, 10); // Show only the date
$reg_ex = "\-"; // Look for what?
$replace_word = "/"; // Replace with what?
$datestart = ereg_replace($reg_ex, $replace_word, $datestart);
$dateend = ereg_replace($reg_ex, $replace_word, $dateend);
$datestart_pieces = explode("/", $datestart);
$year = $datestart_pieces[0];
$month = $datestart_pieces[1];
$day = $datestart_pieces[2];
$datestart = $month.'/'.$day.'/'.$year;
$dateend_pieces = explode("/", $dateend);
$year = $dateend_pieces[0];
$month = $dateend_pieces[1];
$day = $dateend_pieces[2];
$dateend = $month.'/'.$day.'/'.$year;
echo $datestart.' - '.$dateend;
Enjoy!
EpiphanySales added 11 Minutes and 11 Seconds later...
Ha. Was just notified by someone else that it can be more efficiantly this way. Glad I am so ignorant. 
PHP Code:
$dates = explode('-', $datestart);
$newdatestart = "$dates[1]/$dates[2]/$dates[0]";
Bookmarks