Solved

PHP Convert dates

Posted on 2011-09-06
6
275 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
Comment Utility
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
Comment Utility
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
Comment Utility
$olddate = "06/09/2011";

$unixtimestamp = strtotime($olddate);

$newdate = date("Y-m-d",$unixtimestamp);
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
Try this

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

Expert Comment

by:OmniUnlimited
Comment Utility

<?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
Comment Utility
Well, since you neglected to at least thank others who tried to help you, ....

You're welcome, anyway.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses four methods for overlaying images in a container on a web page
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…
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.

771 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

10 Experts available now in Live!

Get 1:1 Help Now