0

I have a PHP variable '$date', and it's value is: y/m/d h:i:s format.

e.g: $date = "2014-11-10 17:25:00";

I want to change this format to m/d/y h:i:s format, so that I'm using PHP code below. It's working fine but is there any PHP function to do it in one line of code ?

$date = "2014-11-10 17:25:00";
$explode = explode(" ", $date);
$part1 = $explode[0];
$part2 = $explode[1];
$explode = explode("-", $part1);
$year = $explode[0];
$month = $explode[1];
$day = $explode[2];
$created_date = "$month-$day-$year $part2";
ObserveDBA
  • 105
  • 1
  • 2
  • 12
Babu
  • 455
  • 2
  • 14
  • 33

1 Answers1

0

You can use date() & strtotime() functions. Example:

$date = "2014-11-10 17:25:00";
echo date('m-d-Y H:i:s', strtotime($date));

Output:

11-10-2014 17:25:00
MH2K9
  • 11,951
  • 7
  • 32
  • 49