Solved

How do i split a date with php

Posted on 2007-12-05
11
2,903 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
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…

717 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