0

I am struggling with a date format. I need to adjust the display of some dates in a WordPress project.

What I have is German date in the format D, d. MM yyyy looking like this: Fr, 6. Mai 2022

I want to convert it to yyyy-mm-dd = 2022-05-06, but I can't get it to work. I have tried to use date_parse_from_format and date_create_from_format, but it seems to fail because of the German month and day names.

$date_german = 'Fr, 6. Mai 2022';
$date_english = 'Fri, 6. May 2022';
print_r(date_create_from_format('D, d. F Y', $date_german)); // doesn't work
print_r(date_create_from_format('D, d. F Y', $date_english)); // works ()

I am also a bit confused since in WordPress the format is D, d. MM yyyy, but I can parse it in English with D, d. F Y.

I also tried to setLocale to de_DE before formatting, but still same problem.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
xDrago
  • 1,359
  • 2
  • 15
  • 32

0 Answers0