[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP Convert dates

Posted on 2011-09-06
6
Medium Priority
?
320 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

656 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