Solved

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

Posted on 2008-06-16
5
1,154 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 400 total points
Comment Utility
$newDate = date('dd/mm/YYYY', strtotime('$x));
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 400 total points
Comment Utility
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
Comment Utility
"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
Comment Utility
THANKS!
0
 

Author Comment

by:gingera
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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 …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

12 Experts available now in Live!

Get 1:1 Help Now