0

I've a string like this: 2018-02-21 15:10:23. I need to show a date like this '23 Febbraio 2018' and, I used this code to convert the string to a DateTime:

$post_date_to_DateTime = new DateTime($post_date_string);
$post_date = $post_date_to_DateTime->format('Y-m-d');

Now, I have to extract Month in format Text and day and year in number to compose the date (in Italian). There's a fast method using some php date functions or I have to create an array with all Months Italian names and then create a specific string?

Thanks in advance!

  • 3
    `format('d F Y');` Take a look here about the format options: http://php.net/manual/de/function.date.php – Tyr Feb 23 '18 at 10:55

4 Answers4

1

Try This (Your Requirement):

$post_date = date('j F Y', strtotime('2018-02-21 15:10:23'));

For More Formatting Please check PHP - date http://php.net/manual/en/function.date.php

Robin Rai
  • 392
  • 3
  • 14
1
setlocale(LC_TIME, 'it_IT');
echo (strftime("%e %B %Y", strtotime("02/28/2002")) );

/*OUTPUT*/
28 febbraio 2002

Read before this https://stackoverflow.com/a/1114547/5803974

Satish
  • 696
  • 1
  • 11
  • 22
0

according to https://secure.php.net/manual/en/function.date.php you can get the english month name with:

$post_date_to_DateTime->format('F');

to get italian names you will have to define them by your self, like you already guessed.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
wayneOS
  • 1,427
  • 1
  • 14
  • 20
0

use strftime — Format a local time/date according to locale settings

echo strftime('%e %B %Y', strtotime('2018-02-21 15:10:23'));

%d Two-digit day of the month (with leading zeros) 01 to 31

%e Day of the month, with a space preceding single digits. 1 to 31

%B Full month name, based on the locale January through December

%Y Four digit representation for the year Example: 2038

For more info Click Here

Bhaskar Jain
  • 1,651
  • 1
  • 12
  • 20