Solved

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

Posted on 2008-06-16
5
1,164 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Installer 5 38
what do I need to host my own web sites? 13 51
Need to remove %20 from url in get 17 36
Echo Multiple values from multiple records 19 43
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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 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…

828 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