How do i split a date with php

Have field labeled surgery_date and is either in db as 2007-11-15 or 11/15/2007. It was entered both ways.

I want date as latter option for my output (ie. 11/15/2007)

If I do this for the former result will it keep my latter result intact as 11/15/2007 or will it take 11/15/2007 and make it null because it can't split it. What will happen to the output if I give it a value of 11/15/2007 and run it through the split below? Is there a way to split based on - and /

$surgery_date = $surgery_date;
list($month, $day, $year) = split('[/.-]', $surgery_date);
$surgery_date = "$month/$day/$year";
LVL 1
pdheadyAsked:
Who is Participating?
 
nizsmoConnect With a Mentor DeveloperCommented:
Try:

<?php
$surgery_date = "2007-11-15";
$date = date("m/d/Y",strtotime($surgery_date));
echo $date;
?>
0
 
nizsmoDeveloperCommented:
This will work for both format input: 2007-11-15 and 11/15/2007, will always output the format 11/15/2007.

Hope this helps.
0
 
nacker2000Commented:
To reformat try:
<?php
	$date = '2007-11-15';
	print(date('d/m/Y', strtotime($date)));
?>

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nacker2000Commented:
Oops... soz nizsmo I didn't refresh my page :)
0
 
nizsmoDeveloperCommented:
no problem :)
0
 
pdheadyAuthor Commented:
nacker u should get some points too. ;-)

how does this site work, what do u get for getting points??
0
 
nacker2000Commented:
No its ok nizsmo answered it correctly before I did. We both suggested the same thing, but I was too slow :)
0
 
nizsmoDeveloperCommented:
pdheady:

just split the points as you see fit :)
0
 
pdheadyAuthor Commented:
Ok, so how how does this site work. What is the benefit to getting points? I just ask questions.
0
 
nacker2000Commented:
If you get so many point per month you get a free premium membership plus theres more things...
0
 
nizsmoDeveloperCommented:
no big benefits, you get a better ranking (look at the right panel for ranking) and occasionally a free t-shirt and that is about all :)

Thats why many people say, EE has a lot of volunteers :)
0
All Courses

From novice to tech pro — start learning today.