1

Possible Duplicate:
Format mysql datetime with php

How to convert the following:

2010-12-07 12:00:00

into:

December, 7th, 2010
Community
  • 1
  • 1
Keith Donegan
  • 26,213
  • 34
  • 94
  • 129
  • 2
    *(reference)* http://de3.php.net/manual/en/function.date.php – Gordon Dec 09 '10 at 21:41
  • 1
    There will always be people who spoonfeed even the laziest questions. Wonderful, five identical answers. Bleh. Just what this place needs. Yet [another how to format date question](http://stackoverflow.com/search?q=+format+date+php) – Gordon Dec 09 '10 at 21:44
  • 1
    @Gordon: It's the fastest way to get rep :) – Jonah Dec 09 '10 at 21:51
  • This question really does duplicate over 15 other incarnations of the same thing. – Tim Post Feb 23 '11 at 17:26

5 Answers5

10
echo date("F, jS, Y", strtotime("2010-12-07 12:00:00"));

http://php.net/manual/en/function.date.php

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
4

Check out the date function.

$myDate = strtotime('2010-12-07 12:00:00');
$formattedDate = date('F, jS, Y', $myDate)
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
  • Odd to call a timestamp myDate – Dan Grossman Dec 09 '10 at 21:42
  • Yeah, I guess that's what happens when you take 2 seconds instead of 3 to write a response. I suppose the same could be said of @Dutchie432's response using `$d` instead of `$t` and @John Giotta's response using the same exact naming convention as mine. – Matt Huggins Dec 09 '10 at 21:43
  • Matt is right... The same could be said about my post. With quick one-shot calculations like that, I see no reason why the original variable can't reflect that it will end up being used to calculate a date. In my case, `d` stands for `aDateWillBeCalculatedUsingThisTimestampWhichIsNotInDateFormatYet` – Dutchie432 Dec 13 '10 at 13:28
3

Use date_format

http://www.php.net/manual/en/function.date-format.php

$date = date_create('2010-12-07 12:00:00');
echo date_format($date, 'F, jS, Y');
John Giotta
  • 16,432
  • 7
  • 52
  • 82
3

echo date('F, jS, Y',strtotime('2010-12-07 12:00:00'));

mikelbring
  • 1,492
  • 2
  • 13
  • 24
3
$d = strtotime('2010-12-07 12:00:00');
echo date('F, jS, Y', $d); 
Dutchie432
  • 28,798
  • 20
  • 92
  • 109