Solved

How do i split a date with php

Posted on 2007-12-05
11
2,896 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now