-4

I have a string that's currently 16/06/2012 and I'd like to convert it into 2012-06-16.

How do I do this?

imjp
  • 6,495
  • 10
  • 48
  • 58
  • Was it really too hard to look at one of the thousands of identical questions in the "related" box that popped up when you typed in the question title? Or to Google `convert php date string`? – Pekka Mar 02 '12 at 21:45
  • 3
    Interesting that Pekka just commented. Here is a reference to the answer Pekka gave. http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php – Shattuck Mar 02 '12 at 21:47

2 Answers2

2
$date_array = explode("/","16/06/2012");

$new_date = $date_array[2]."-".$date_array[1]."-".$date_array[0];
Wiseguy
  • 20,522
  • 8
  • 65
  • 81
Kaushtuv
  • 479
  • 5
  • 17
0
date("Y-m-d", strtotime(implode("/", array_reverse(explode("/", "16/06/2012")))))
mc.watras
  • 381
  • 3
  • 10
  • 2
    At that point, why even use `date()` and `strtotime()`? When you `implode()`, just use "-" instead of "/" and you're done. – Wiseguy Mar 02 '12 at 21:58