Solved

How do i split a date with php

Posted on 2007-12-05
11
2,901 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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