Solved

How do i split a date with php

Posted on 2007-12-05
11
2,900 Views
Last Modified: 2013-12-12
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
Comment
Question by:pdheady
  • 5
  • 4
  • 2
11 Comments
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20415091
Try:

<?php
$surgery_date = "2007-11-15";
$date = date("m/d/Y",strtotime($surgery_date));
echo $date;
?>
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415095
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
 
LVL 5

Expert Comment

by:nacker2000
ID: 20415109
To reformat try:
<?php
	$date = '2007-11-15';
	print(date('d/m/Y', strtotime($date)));
?>

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 5

Expert Comment

by:nacker2000
ID: 20415114
Oops... soz nizsmo I didn't refresh my page :)
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415118
no problem :)
0
 
LVL 1

Author Comment

by:pdheady
ID: 20415220
nacker u should get some points too. ;-)

how does this site work, what do u get for getting points??
0
 
LVL 5

Expert Comment

by:nacker2000
ID: 20415241
No its ok nizsmo answered it correctly before I did. We both suggested the same thing, but I was too slow :)
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415245
pdheady:

just split the points as you see fit :)
0
 
LVL 1

Author Comment

by:pdheady
ID: 20415252
Ok, so how how does this site work. What is the benefit to getting points? I just ask questions.
0
 
LVL 5

Expert Comment

by:nacker2000
ID: 20415262
If you get so many point per month you get a free premium membership plus theres more things...
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415275
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question