0

via xml, I am getting variables that give time in this format: 2012-06-25 19:00:00

I'd like it to be converted in this format: June 25 - 7:00PM

I have looked at mktime and strtotime, but im not sure how to handle a format that comes as a date AND time.

  • Look at [`date()`](http://us.php.net/manual/en/function.date.php) or [DateTime](http://us.php.net/manual/en/book.datetime.php) – John Conde Jun 13 '12 at 20:13

2 Answers2

5

As you said, you can use strtotime:

echo date('F-m - h:iA', strtotime($old_format));
alexn
  • 57,867
  • 14
  • 111
  • 145
0
<?php

$input = "2012-06-25 19:00:00";

$dateTimeObject = new DateTime($input);
echo "First way: " . $dateTimeObject->format("F d - g:iA") . "<br>\n";

$date = date("F d - g:iA", strtotime($input));
echo "Second way: " . $date;
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308