Solved

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

Posted on 2008-06-16
5
1,176 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
[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
  • 2
  • 2
5 Comments
 
LVL 49

Accepted Solution

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

Assisted Solution

by:Roonaan
Roonaan earned 400 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 100 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

710 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