I have an array which contains the last 7 days, I loop over that array and every day is stored in $day.
The format looks like this when I echo $day
"2019-09-18"
"2019-09-19"
"2019-09-20"
"2019-09-21"
"2019-09-22"
"2019-09-23"
"2019-09-24"
Now I want to show only the name of the day, so I found this in another SO question:
$string = "2010-11-24";
$date = DateTime::createFromFormat("Y-m-d", $string);
echo $date->format("D") . "<br>";
Which works fine, only when I change the date string into
$string = $day;
I get an error:
Call to a member function format() on boolean
Why is it not working?
My entire code now:
$arr = getLastNDays(7, 'Y-m-d');
foreach($arr as $day) {
$weekdagen = 'SELECT *
FROM orders
WHERE DATE(datum) = '.$day.'';
$weekdagenconn = $conn->query($weekdagen);
$weekdagen = $weekdagenconn->fetch_assoc();
$string = "2010-11-24";
$date = DateTime::createFromFormat("Y-m-d", $string);
echo $date->format("D") . "<br>";
}