Solved

PHP Convert dates

Posted on 2011-09-06
6
310 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
[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
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
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:Cornelia Yoder
ID: 36488027
$olddate = "06/09/2011";

$unixtimestamp = strtotime($olddate);

$newdate = date("Y-m-d",$unixtimestamp);
0
Technology Partners: 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!

 
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:Cornelia Yoder
ID: 36488150
Well, since you neglected to at least thank others who tried to help you, ....

You're welcome, anyway.
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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

707 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