0

I have date cell in my db:createDate This is the format Y-m-d. i.e: 2018-10-31

How can i print it on the screen in this format: October 2018

?

I tried this:

echo date ("Y-M", $mainIndex['createDate'])
Roi
  • 153
  • 1
  • 11
  • php.net search for date function! – Daan Oct 31 '18 at 10:04
  • 3
    Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – ldam Oct 31 '18 at 10:37
  • Possible duplicate of [Convert date to month name & year](https://stackoverflow.com/questions/45138411/convert-date-to-month-name-year) – Dave Oct 31 '18 at 10:43

4 Answers4

2

Use this

echo date ("F Y", strtotime($mainIndex['createDate']));
Sanu0786
  • 571
  • 10
  • 15
-1

You were very close :) second parameter should be an integer (time)

echo date ("F Y", strtotime($mainIndex['createDate']));
simonecosci
  • 1,194
  • 7
  • 13
-1

You can use date format php function something like this

echo date_format($mainIndex['createDate'],"F Y");

For more you can get it from it php date_format and for php date parameters Parameters

Dipendra Deshar
  • 65
  • 2
  • 12
-1

you need to convert the time date unix timestamp

echo date('F Y', strtotime($mainIndex['createDate']));
Mohammad
  • 21,175
  • 15
  • 55
  • 84
Debdip
  • 31
  • 1