Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP MYSQL: How to convert yyyy-mm-dd to dd/mm/yyyy?

Posted on 2008-06-16
5
Medium Priority
?
1,213 Views
Last Modified: 2013-12-13
Hello,

How do I convert $x from "yyyy-mm-dd" to "dd/mm/yyyy" in a PHP script?

Thanks.
0
Comment
Question by:gingera
  • 2
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 1600 total points
ID: 21792355
$newDate = date('dd/mm/YYYY', strtotime('$x));
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 1600 total points
ID: 21792359
Or in a more string-manipulative way:

$newDate = implode('/', array_reverse(explode('-', $x)));
0
 
LVL 2

Assisted Solution

by:Deepika_Rastogi
Deepika_Rastogi earned 400 total points
ID: 21792488
"yyyy-mm-dd" to "dd/mm/yyyy"
Try this ($original is the date in the "yyyy-mm-dd" format) :

function convertdate($original)
{
$year = substr($original,0,4);
$month =substr($orginal,5,2);
$day = substr($original,8,2);

$newdate = "$day/$month/$year";

return $newdate;
}
0
 

Author Closing Comment

by:gingera
ID: 31467548
THANKS!
0
 

Author Comment

by:gingera
ID: 21792806
I have to clarify Roonaan's 1st suggestion should read:

$newDate = date('d/m/Y', strtotime('$x));

not

$newDate = date('dd/mm/YYYY', strtotime('$x));
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

963 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