?
Solved

How do i split a date with php

Posted on 2007-12-05
11
Medium Priority
?
2,904 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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 count occurrences of each item in an array.
Suggested Courses

771 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