smile 22121 smile 22121 - 1 year ago 66
PHP Question

Translating date to default language or selected language

I have to display a date that I pick from my DB, the date is always displayed in english, my site is bilangue, EN/DE.

my PHP code

setlocale(LC_ALL, "de_DE.utf8");
$myDate='2016-06-17'; //example
echo strftime(date_format(date_create($myDate), "l, j F Y "))

But this doesn't work, I get it always in EN
Friday, 17 June 2016

UPDATE : I could use

strftime("%B %e, %G",date_timestamp_get(date_create($myDate)))

I get
Juni 17, 2016
,but then I lose the name of the day so I have to use also

Answer Source

The following code gives the expected result:

setlocale(LC_ALL, "de_DE.utf8");
$myDate='2016-06-17'; //example
echo strftime("%A, %e %B %Y", date_create($myDate)->getTimestamp());

According to the documentation, strftime arguments are a format string and a timestamp. The second argument you provided is not a timestamp.