3

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 date_format

smile 22121
  • 285
  • 4
  • 20

2 Answers2

3

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.

Jocelyn
  • 11,209
  • 10
  • 43
  • 60
0

There're mainly two problems:

  • Don't stick to one proper date data type and mix it with too many strings.
  • Don't use functions as the documentation explains.

The strftime() function expects a Unix timestamp as second argument but date_format() returns a string (it could return a string with a timestamp but it doesn't because of l, j F Y). You are also using strftime() wrong: the first argument is the format, not the timestamp. Additionally, you are using DateTime objects as proxy without any benefit.

Try something simpler:

setlocale(LC_ALL, "de_DE.utf8");
$myDate = strtotime('2016-06-17'); //example
echo strftime('Write proper format there', $myDate);
Álvaro González
  • 142,137
  • 41
  • 261
  • 360