Solved

PHP Convert dates

Posted on 2011-09-06
6
294 Views
Last Modified: 2012-05-12
Can someone help with the syntax to convert dates such as 06/09/2011 to 2011-09-06 please?
0
Comment
Question by:PeterErhard
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 36488017
http://us2.php.net/manual/en/function.strtotime.php

will convert the string to a unix timestamp

http://us2.php.net/manual/en/function.date.php

will convert a unix timestamp to whatever date format you want.
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 36488026
Simple way with explode() function


<?php

$strng = "06/09/2011";
$parse = explode("/", $strng);

$modified_date = $parse[2]."-".$parse[1]."-".$parse[0];

echo $modified_date;



?>

Open in new window

0
 
LVL 27

Expert Comment

by:yodercm
ID: 36488027
$olddate = "06/09/2011";

$unixtimestamp = strtotime($olddate);

$newdate = date("Y-m-d",$unixtimestamp);
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36488041
Try this

echo date('Y-m-d', strtotime($strng))
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36488053

<?php

$date = date_create_from_format('d/m/Y', '06/09/2011');
echo date_format($date, 'Y-m-d');

?>

Open in new window

0
 
LVL 27

Expert Comment

by:yodercm
ID: 36488150
Well, since you neglected to at least thank others who tried to help you, ....

You're welcome, anyway.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to count occurrences of each item in an array.
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…

776 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