This is my code:
<?php
$date_db = "2017-10-12 12:00:00";
setlocale(LC_ALL, "de_DE.UTF-8");
$date_db = strtotime($date_db);
$date_db = strftime("%e. %B %Y, %A, %k:%M Uhr", $date_db);
$date_db = str_replace(":00","",$date_db);
echo $date_db;
?>
The output is: 12. Oktober 2017, Donnerstag, 12 Uhr
This is all right so far. But sometimes there's no time, only a date, like this: $date_db = "2017-10-12 00:00:00";
.
This will output: 12. Oktober 2017, Donnerstag, 0 Uhr
.
In a case like this, I want to have removed the trailing , 0 Uhr
.
I think it should work by using this line of code below the other str_replace
code line: $date_db = str_replace(", 0 Uhr","",$date_db);
.
Whole code:
<?php
$date_db = "2017-10-12 00:00:00";
setlocale(LC_ALL, "de_DE.UTF-8");
$date_db = strtotime($date_db);
$date_db = strftime("%e. %B %Y, %A, %k:%M Uhr", $date_db);
$date_db = str_replace(":00","",$date_db);
$date_db = str_replace(", 0 Uhr","",$date_db);
echo $date_db;
?>
This should output 12. Oktober 2017, Donnerstag
, but output is 12. Oktober 2017, Donnerstag, 0 Uhr
.
What am I doing wrong?