5

Possible Duplicate:
PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL]

Hope everyone is having a great holiday.

I have a date in this format: 23-12-2011 and would like to reverse it into US format 2011-12-23.

Does anyone know how I can do this in PHP? Is there any function for breaking strings up?

Community
  • 1
  • 1
Helen Neely
  • 4,666
  • 8
  • 40
  • 64

2 Answers2

7
$date = DateTime::createFromFormat('d-m-Y', '23-12-2011');
echo $date->format('Y-m-d');

Voila. Check out PHP5s datetime class

Flukey
  • 6,445
  • 3
  • 46
  • 71
4
date("Y-m-d", strtotime("23-12-2011"))
Robin Michael Poothurai
  • 5,444
  • 7
  • 23
  • 36