1

I have a date that I need to convert using PHP date. I've tried a couple different things with no success.

Date coming in: 2011/10/14

Date I need going out: October 2011

Do I need to convert my incoming date to time, and then from time to date going out? I don't understand.

Romes
  • 3,088
  • 5
  • 37
  • 52
  • possible duplicate of [Convert date/time (PHP)](http://stackoverflow.com/questions/2412402/convert-date-time-php) Virtually all questions about converting dates in PHP can be solved by `strtotime()` or `mktime()` or the `DateTime` class. Some more resources: http://stackoverflow.com/search?q=php+convert+date – Wesley Murch Mar 12 '12 at 19:30
  • No need to convert it to time: http://php.net/manual/en/book.datetime.php – PeeHaa Mar 12 '12 at 19:31

4 Answers4

6

You can use DateTime and its format() method:

$date = new DateTime('2011/10/14');
echo $date->format('F Y');
Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
3

date("F Y", strtotime($date));

ThePrimeagen
  • 4,462
  • 4
  • 31
  • 44
0
$date_out = date("F Y", strtotime($date_in));

strtotime converts a string value to a timestamp.

date converts a timestamp into a string representation based on the format provided as the first argument.

danielrsmith
  • 4,050
  • 3
  • 26
  • 32
0

You can almost certainly accomplish that and pretty much almost problem related to date/time convertion using the DateTime class of PHP core.

Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79