[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2906
  • Last Modified:

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";
0
pdheady
Asked:
pdheady
  • 5
  • 4
  • 2
1 Solution
 
nizsmoDeveloperCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now