1

Possible Duplicate:
Convert one date format into another in PHP

I've got a string in the date format m-d-Y, and I need it d-m-Y. How can I do that in PHP 5.2?

The most common answer DateTime::createFromFormat() here on stackoverflow doesn't work in PHP 5.2, and new DateTime() + $date->format('d-m-Y') doesn't change the format.

Thanks,
Thew

Community
  • 1
  • 1
Thew
  • 15,789
  • 18
  • 59
  • 100

2 Answers2

5
$parts = explode('-', $dateString);
var_dump($parts[1] . '-' . $parts[0] . '-' . $parts[2]);
zerkms
  • 249,484
  • 69
  • 436
  • 539
-2
date('d-m-Y',strtotime($yourdatestring));
ryanbwork
  • 2,123
  • 12
  • 12
  • AFAIK, PHP interprets x-y-z dates as d-m-y and x/y/z dates as m/d/y, so this won't work. – Matt Aug 01 '12 at 20:53
  • so is this solution ever applicable to date conversions being that strtotime doesn't know how to differentiate between months and days when they're both <= 12? – ryanbwork Aug 01 '12 at 21:04